Jump to content

[SOLVED] Select WHERE problem


bschultz

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/52654-solved-select-where-problem/
Share on other sites

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"); 
}
?>

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.