12-06-2010, 07:45 PM
|
#1 (permalink)
|
|
The Visitor
Join Date: Dec 2010
Posts: 2
Thanks: 0
|
help with php json and javascript
right i no this must be simple to achieve but i cnat get my head round it.
What i want to no is after i create my array in php i encode it with "json_encode and echo it out.
it comes out in the right format
but how do i use it in the javascript tags.
Any help would be greatly appreciated
Code below
<?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 '<pre>' . json_encode($array) . '</pre>';
?>
<html>
<head>
<script type="text/javascript">
</script>
</head>
<body>
</body>
</html>
|
|
|
|