When i use the code below, im getting this error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
when returning the data, anyone can fix it? Thanks!
<?php
$mysql_server_name="localhost";
$mysql_username="";
$mysql_password="";
$mysql_database="";
$conn=mysql_connect($mysql_server_name, $mysql_username,
$mysql_password);
?>
<?php
$result = mysql_query("SELECT * FROM users");
$arrays = array();
while ($row = mysql_fetch_assoc($result)) {
foreach ($row as $key => $val) {
if (!array_contains_key($key)) {
$arrays[$key] = array();
}
$arrays[$key][] = $val;
}
}
?>
<script type="text/javascript">
<?php
foreach ($arrays as $key => $val) {
print 'var ' . $key . ' = ' . json_encode($val) . ";\r\n";
}
?>
</script>