Jump to content

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

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.