klb Posted April 13, 2007 Share Posted April 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/46899-strange-query-behavior/ Share on other sites More sharing options...
craygo Posted April 13, 2007 Share Posted April 13, 2007 The statement is valid but please post your code to display your results, may have an error in the query code. Ray Quote Link to comment https://forums.phpfreaks.com/topic/46899-strange-query-behavior/#findComment-228642 Share on other sites More sharing options...
klb Posted April 13, 2007 Author Share Posted April 13, 2007 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']; Quote Link to comment https://forums.phpfreaks.com/topic/46899-strange-query-behavior/#findComment-228653 Share on other sites More sharing options...
klb Posted April 13, 2007 Author Share Posted April 13, 2007 it's worth noting also that i commented out the function call and put the query directly in the main page and had the same result. Quote Link to comment https://forums.phpfreaks.com/topic/46899-strange-query-behavior/#findComment-228654 Share on other sites More sharing options...
craygo Posted April 13, 2007 Share Posted April 13, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/46899-strange-query-behavior/#findComment-228699 Share on other sites More sharing options...
klb Posted April 13, 2007 Author Share Posted April 13, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/46899-strange-query-behavior/#findComment-228733 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.