bschultz Posted May 23, 2007 Share Posted May 23, 2007 I'm getting an error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in daily.php on line 27 Here's my code... <?PHP //do your normal mysql setup and connection calls $dbc = mysql_pconnect('xxx','xxx','xxx'); mysql_select_db('news',$dbc); //now get stuff from a table $sql = "SELECT date, story FROM stories WHERE ids = date"; //now spit out the table and rows for the table ?> <strong> News Archive </strong><br> <br> <?php $rs = mysql_query($sql,$dbc); $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; echo "<font size='3'>".$row[date]."<br>"; echo "<font size='3'>".$row[story]."<br><br>"; } if (! $matches) { echo ("<br>There are no news items for today"); } echo "</TABLE>"; ?> The variable ids is being passed in the url like this: http://domain.com/localnews/daily.php?ids=2007-05-23 No matter how I put the WHERE clause (order, quotes, no quotes) it doesn't return a record...even though I know there are records that match the date. ANy ideas? Thanks. Brian Quote Link to comment https://forums.phpfreaks.com/topic/52654-solved-select-where-problem/ Share on other sites More sharing options...
Wildbug Posted May 23, 2007 Share Posted May 23, 2007 (You should be checking mysql_error(), too, at least while developing.) Try this: $sql = "SELECT date, story FROM stories WHERE date='$ids'"; Quote Link to comment https://forums.phpfreaks.com/topic/52654-solved-select-where-problem/#findComment-259902 Share on other sites More sharing options...
bschultz Posted May 23, 2007 Author Share Posted May 23, 2007 I had the error checking in before...it was 1064... As for the new code, it removes the error message, but still doesn't return as true. Thanks for the help Wildbug! Quote Link to comment https://forums.phpfreaks.com/topic/52654-solved-select-where-problem/#findComment-259911 Share on other sites More sharing options...
bschultz Posted May 23, 2007 Author Share Posted May 23, 2007 For further debugging, I added an echo of $rs to see what exactly was in the query... It returned this: Resource id #3 Now I'm REALLY confused. Quote Link to comment https://forums.phpfreaks.com/topic/52654-solved-select-where-problem/#findComment-259934 Share on other sites More sharing options...
Wildbug Posted May 23, 2007 Share Posted May 23, 2007 mysql_query() returns a resource "handle," not an array or a bunch of data or anything. The other mysql_fetch_* functions fetch data from this handle. So, when you print it out, PHP just tells you it's a resource and what id it is. <?php $rs = mysql_query($sql,$dbc); if (mysql_errno()) echo "MySQL Error: ",mysql_error(),"<br>\n"; if ($rs && mysql_num_rows($rs)) { echo mysql_num_rows()," matches<br>\n"; while ($row = mysql_fetch_assoc($rs)) { echo "<font size='3'>$row[date]<br>"; echo "<font size='3'>$row[story]<br><br>"; } } else { echo ("<br>There are no news items for today"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52654-solved-select-where-problem/#findComment-259957 Share on other sites More sharing options...
bschultz Posted May 23, 2007 Author Share Posted May 23, 2007 Thanks again, Wildbug... No error, just a empty result... Quote Link to comment https://forums.phpfreaks.com/topic/52654-solved-select-where-problem/#findComment-259960 Share on other sites More sharing options...
bschultz Posted May 23, 2007 Author Share Posted May 23, 2007 Thanks Wildbug... I got it $sql = "SELECT * FROM stories WHERE date='$_GET[ids]'"; Since globals are off...like they should be...I needed to use $_GET. Old dog, meet new tricks! Quote Link to comment https://forums.phpfreaks.com/topic/52654-solved-select-where-problem/#findComment-259977 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.