Ben
Ben

Reputation: 369

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!

Upvotes: 1

Views: 80

Answers (2)

Dev. Joel
Dev. Joel

Reputation: 1137

declare your array as follows

$json = array();

and see if you have results before your result

if ($amountoflikes)
{
  while(){...}
}

Upvotes: 1

Rick Chen
Rick Chen

Reputation: 181

Try declaring $json as an array above the while:

$json = array();

Upvotes: 1

Related Questions