help required for noobie(no hair left)
all i want to be able to do is use the individual elements of the array in javascript eg companyname or companyimage
but just getting my head in my hand.
mysql_select_db("herefordinfo") or die(mysql_error());
echo "Connected to Database";
$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[] = "{ {$pubs['id']}, {$pubs['companyname']}, {$pubs['companyinfo']}, {$pubs['companyimage']} }";
}
echo 'var pub = [' . implode(', ', $array) . '];'; // this
?>
<html>
<head>
<script type="text/javascript">
var jsArray = <?php echo json_encode($array); ?>;
document.write(jsArray); //this
</script>
</head>
<boby></body>
</html>
both php and javescritp output the results below
{ 1, lichfield vaults, 10 church street hereford , lich.jpg },{ 2, Black Lion, bridge street, blacklion.jpg },{ 3, Saracens Head, st martins street, saracens.jpg }