Ben Ben - 2 months ago 7
MySQL Question

Reference specific row's column value from array

I have read a-lot of answers on this but they don't seem to be working.

I have the following code:

$amountoflikes=mysql_query("SELECT * FROM `uc_likes` WHERE `dwable` = '372'");


This returns the following:

enter image description here

If I wanted to echo the value of
dwable
in the 2nd row for instance (not involving the initial query).

I've tried:

while($row3 = mysql_fetch_assoc($amountoflikes)){
$json[] = $row3;
}
echo json_encode($json);


But this returns null.

I'm currently using PHP 5.5 (native).

I'm not using MySQLi or MySQL PDO.

Can someone tell me where I'm going wrong. Ideally I'd prefer not to use a loop but I don't know if that's possible.

Thanks!

Answer

Try declaring $json as an array above the while:

$json = array();
Comments