Jump to content

Recommended Posts

i have a simple query:

 

SELECT clientnotes FROM notes WHERE orderid = '$orderid'

 

where orderid is a valid orderid in my database.  there are two cases:  one where the notes return, and one where there are notes in the database but they don't return via php.  for the case where they don't return, i have var_dumped the query to the screen and run the exact query in mysqlyog, and it returns results.  but the php doesn't return anything.  it doesn't error on the query, it simply returns an empty set.  i'm baffled!  the notes are in the database and sometimes the query works, but apparently only for certain orders.  it never sometimes works for one order and sometimes not.  it either works for an orderid or it doesn't.  can anyone think of anything i might be missing?  i checked the database to make sure i had the right one, and i do.  i'm frustrated that such a simple query could cause me so much grief!  any help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/46899-strange-query-behavior/
Share on other sites

the code is valid, because it works for some orderids, but here it is, thanks:

 

Function DBGetNotes($orderid) {

$query = "SELECT clientnotes FROM notes WHERE orderid = '$orderid'";

        $qry = mysql_query($query) or die ("could not get notes  " . mysql_error());

$res = mysql_fetch_array($qry);

        return $res;

}

 

then in the main code:

 

$resnotes = $DBQ->DBGetNotes($orderid);

$cnotes = $resnotes['clientnotes'];

If you don't loop through the results you will only get the last row of the result

 

Function DBGetNotes($orderid) {
$result = array();
   $query = "SELECT clientnotes FROM notes WHERE orderid = '$orderid'";
        $qry = mysql_query($query) or die ("could not get notes  " . mysql_error());
   while($res = mysql_fetch_array($qry)){
        $result[] = $res['clientnotes'];
   }
return $result;
}

 

Now the function will return the array with all the results

 

Ray

there should only ever be one row in the db for each orderid, that gets appended to each time a note is added.  but your answer helped me figure out that another part of the script was writing to the notes table multiple times instead of appending to the same row.  thanks for your help.

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.