Tuesday, 28 August 2018
Subscribe to:
Post Comments (Atom)
$result = mysql_query("SELECT zebra_id FROM zebra WHERE user_id = '$id' AND pref = '1'")
or die(mysql_error());
$array = mysql_fetch_row($result);
echo json_encode($array);
["986"]
mysql_fetch_row()
only fetchs one row as the name implies. So your error is obvious.mysql_fetch_array()
won't work unless you iterrate through the entire result set*. You just don't call it once and expect to get the entire result set in an array.$result = mysql_query("SELECT zebra_id FROM zebra WHERE user_id = '$id' AND pref = '1'")
or die(mysql_error());
$array = array();
while($row = mysql_fetch_assoc($result)) {
$array[] = $row;
}
echo json_encode($array);
mysql_*
functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.Hello Friends! I am Ramana a part time blogger from Hyderabad.
0 comments:
Post a Comment