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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.