I am trying to pass a php value, obtained from a join query, to a javascript function. The javascript function will open a new window and show some data based on the passed value.My query works fine but the php value is not passed to the JS function.
My code :
<script type=text/javascript>
function product(var) {
window.open( view_product_info.php?var, myWindow,
status = 1, height = 300, width = 300, resizable = 0 )
}
</script>
\ the line where i am trying to pass the php varibale
echo '<td align=center ><a href=javascript:product('.$product_id.');> <br/> '.$row['product_name'].'</a></td>';
why the php value $product_id is not passed to the product function.
Thanks in advance.
The code:
<script type=text/javascript>
<!--
function product(var) {
window.open( view_product_info.php?id, myWindow,
status = 1, height = 300, width = 300, resizable = 0 )
}
function company() {
window.open( index.php, myWindow,
status = 1, height = 300, width = 300, resizable = 0 )
}
function category() {
window.open( index.php, myWindow,
status = 1, height = 300, width = 300, resizable = 0 )
}
//-->
<?php include(includes/header.php);
$search = $_POST['search'];
$sql= my query1..;
$sql2= my query2;
$result=mysql_query($sql);
$result2=mysql_query($sql2);
if($result) {
echo '<center>';
echo '<table cellpadding=0 cellspacing=0 border=1 width=100%>';
echo '<tr><th>Sr No.</th><th>Product Name</th><th>Company Name</th> <th>Category</th></tr>';
$number=1;
while ($row = mysql_fetch_array($result)){
$row2 = mysql_fetch_array($result2);
echo $product_id=$row2[product_id];
echo '<tr> ';
echo '<td align=center >'.$number.'</td>';
echo '<td align=center ><a href=javascript:product('<?= $product_id?>')>
''';
echo '<td align=center><a href=javascript:company() ><br/> '.$row['company_name'].'</td>';
echo '<td align=center><a href=javascript:category() ><br/> '.$row['category_name'].'</td>';
$number=$number+1;
}echo '</tr>';
echo'</table>';
echo'</center>';
}
else {
echo No data found;
//echo mysql_error();
}
}
}
?>