12-06-2010, 09:29 PM
|
#2 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Posts: 166
Thanks: 0
|
You would set the output of the PHP as a variable in the javascript. You then could access the data using the javascript variable/object.
PHP Code:
<html> <head>
<script type="text/javascript"> <?php mysql_connect("localhost", "root", "password") or die(mysql_error()); mysql_select_db("herefordinfo") or die(mysql_error());
$dbQuery = 'SELECT * FROM companies'; $dbResult = mysql_query($dbQuery) or die ("Could not read data because " . mysql_error()); $RowCount = mysql_numrows($dbResult);
while ($pubs = mysql_fetch_assoc($dbResult)) { $array[] = array('id'=>$pubs['id'],'companyname'=>$pubs['companyname'],'companyinfo'=>$pubs['companyinfo'],companyimage=>$pubs['companyimage']);
} //echo '<pre>' . print_r($array,true) . '</pre>'; echo 'var data = ' . json_encode($array);
?>
alert(data[0].companyname);
// if you have firebug console.dir(data);
</script>
</head> <body> </body> </html>
__________________
Eric
|
|
|
|