Topic: PhP variable/code inside jquery script

Hi All

I'm in need of assistance, not sure if this is possible.

I'm using jquery to add a row in a table with an onclick action.

<?php
$sql = "SELECT `id`,`emp_name`,`emp_surname` FROM `bcs_employee` ORDER BY `emp_surname`";
$result = $mysqli->query($sql);
while($myrow = $result->fetch_assoc()){
$row .= "<option value=\"$myrow[id]\">$myrow[emp_name] $myrow[emp_surname]</option>";
}


$objResponse->script('
$( "#blaster" ).click(function() {
var index = 8;
var newRow = "<tr id=\"extra\">" +
"<td height=\"25\">&nbsp;</td>" +
"<td>&nbsp;</td>" +
"<td>&nbsp;</td>" +
"<td><select name=\"base_blaster\" id=\"base_blaster\"><option value=\"\">--- Select Blaster ---</option>" +
"<option value=\"\">option</option>" +
"<?php echo $row ?>" +
"</select></td>" +
"<td id=\"del\"><span style=\"cursor:pointer\">remove</span></td>" +
"<td>&nbsp;</td>" +
"<td>&nbsp;</td>" +
"<td>&nbsp;</td>" +
"</tr>";
$("#tableId > tbody > tr").eq(index-1).before(newRow);
});
$("#tableId").on("click","#del span",function(){$(this).closest("#extra").remove();
});
');
return $objResponse;
?>

Now what I need is to get names from a database and add them to my select <option>. In the current code $row contains the info I need but for some reason I cant find a way to pass the php vairiable to the jquery function. I also have tried to make $row an php array and pass it via jason but also with no luck.

Thanks!

Re: PhP variable/code inside jquery script

RESOLVED

For those who would like to know:

$objResponse->script('
$( "#blaster" ).click(function() {

var index = 8;
var newRow = "<tr id=\"extra\">" +
"<td height=\"25\">&nbsp;</td>" +
"<td>&nbsp;</td>" +
"<td>&nbsp;</td>" +
"<td id=\"selTd\">&nbsp;</td>" +
"<td id=\"del\"><span style=\"cursor:pointer\">remove</span></td>" +
"<td>&nbsp;</td>" +
"<td>&nbsp;</td>" +
"<td>&nbsp;</td>" +
"</tr>";
$("#tableId > tbody > tr").eq(index-1).before(newRow);

$.ajax({
    type: "POST",
    url: "functions/process2.php",             
    dataType: "html",                 
    success: function(data){
        $("#selTd").html(data);
        //alert(data);
    }
});

});

$("#tableId").on("click","#del span",function(){$(this).closest("#extra").remove();
});

');

process2.php page:

<?php
$dis = <<<EOF_
<select name="base" id="base">
           <option value="">--- Select ---</option>
EOF_;
$mysqli = mysqli_connect( "host", "user", "pass", "db", 3306 ) or die( mysqli_connect_error());
$sql = "SELECT `id`,`emp_name`,`emp_surname` FROM `bcs_employee` ORDER BY `emp_surname`";
$result = $mysqli->query($sql);
while($myrow = $result->fetch_array()){
$dis .= <<<EOF_
<option value="$myrow[id]">$myrow[emp_name] $myrow[emp_surname]</option>
EOF_;
}
$dis .= <<<EOF_
</select>
EOF_;
echo $dis;
?>