Jump to content

mysql_fetch_array needs refference and not boolean warning


nzorb

Recommended Posts

I've got this and it gives me that warning. Row is null before and after the command. What am I doing wrong?

 

$row=mysql_fetch_array(mysql_query("SELECT I.ITEM_ID AS ID,I.DESCR AS DESCR,W.QUANTITY AS QUANT,W.PRICE AS PRICE FROM ITEM I JOIN WANTS_TO_BUY W ON I.ITEM_ID=W.ITEM_ID JOIN USER U ON U.USERNAME=W.USERNAME WHERE U.USERNAME='%id'"));

 

(I also posted this in php help cause I'm not sure where it belongs, please tell me so I can delete the wrong post)

the result should be fine, if by checking you mean something simple like this:

 

if ($result=mysql_query("SELECT I.ITEM_ID AS ID,I.DESCR AS DESCR,W.QUANTITY AS QUANT,W.PRICE AS PRICE FROM ITEM I JOIN WANTS_TO_BUY W ON I.ITEM_ID=W.ITEM_ID JOIN USER U ON U.USERNAME=W.USERNAME WHERE U.USERNAME='%id'"))

    $row=mysql_fetch_array($result);

else

    echo 'error';

 

I've done that and get the same error.

 

PS: tnx for moving it, I wasn't sure where it belonged, it has a bit of both.

A better way is (IMHO)

<?php
$q = "SELECT I.ITEM_ID AS ID,I.DESCR AS DESCR,W.QUANTITY AS QUANT,W.PRICE AS PRICE FROM ITEM I JOIN WANTS_TO_BUY W ON I.ITEM_ID=W.ITEM_ID JOIN USER U ON U.USERNAME=W.USERNAME WHERE U.USERNAME='%id'";
$rs = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error());
$row = mysql_fetch_assoc($rs);
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.