0

I've a php function to get some data from mysql database:

function get_persons() {
    $result=dbquery("SELECT id,name,surname FROM ".DB_PERSONS." ORDER BY id ASC");
    while ($person = dbarray($result)){
        $id=$person['id'];
        echo "<option value='$id'>$person['name'] - $person['surname']</option>";
    }
}

And i've a javascript code:

$edit_buttonoptions = array("#pager", 
    array("title"=>"Takım Seç","buttonicon"=>"ui-icon-mail-open","caption"=>"Takım Seç", "onClickButton"=>"js: 
 var jspersonvar;
 jspersonvar = "<?php get_persons();?>"
function(){
    var selr = jQuery('#grid').jqGrid('getGridParam','selrow');
    var rowData = jQuery('#grid').jqGrid('getRowData', selr);
    var kelr = jQuery('#grid').jqGrid('getCell', selr, 'bilinen_adi');
    var fotograf = jQuery('#grid').jqGrid('getCell', selr, 'logo');
    if(selr)
        miktar=miktar+1,
        pp='takimlar',
        nm=pp + miktar,
        jQuery('#takimlar').append('<div id=' + nm + '>'),
        jQuery('#'+ nm +'').append('<div style=text-align:center;>'+fotograf+'<input type=hidden name=takim'+ miktar +' value=' + selr + ' />'),
        jQuery('#'+ nm +'').append('<select name=sezon'+ miktar +' id=sezon'+ miktar +'>'+jspersonvar+'</select>'),
        jQuery('#'+ nm +'').append('' + kelr + ''),
        jQuery('#'+ nm +'').append('</div>'),
        jQuery('#'+ nm +'').append('</div><br />'),

      alert('' + kelr + ' Takımı Seçildi')
    else
    alert('Lütfen Bir Takım Seçiniz!')
    return false;
    }"),
); 
$grid->callGridMethod("#grid", "navButtonAdd", $edit_buttonoptions);

It doesn't work, I've tried several things but no luck...

2
  • What is expected? And what dosen't work? Commented Mar 17, 2012 at 16:07
  • 1
    put " around <?php get_persons(); ?> Commented Mar 17, 2012 at 16:07

1 Answer 1

1

You need to put the variable in quotes as it will look like this when the server renders the page:

jspersonvar = <option value='$id'>......

When you have quotes around it, jspersonvar will be treated as a string and you can do what you will with it.

jspersonvar = "<?php get_persons();?>"

Just be warned, any " in your database that get displayed will screw up your javascript.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.