Forum Moderators: coopster

Message Too Old, No Replies

Debugging query error?

         

adammc

1:13 am on Jun 9, 2007 (gmt 0)

10+ Year Member



Hi guys,

Can anyone possibly help me understand why the following query is producing:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

[php]
<?

include("../config.php");

// Connect to database
$cid = mysql_connect($host,$username,$dbpass);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
mysql_select_db("$db");

// define the maximum results to show (set in config file)
$max_results = $max_articles;

// Get the data from the Database
$query = "SELECT article_id, name, date from Articles LIMIT $max_results ORDER BY article_id DESC";

$result = mysql_db_query($db,"$query",$cid);
if (!$result) { echo("ERROR: " . mysql_error() . "\n$result\n"); }

while($row=mysql_fetch_array($result))
{
?>

<tr class="row-a">
<td class="first"><? echo("$row[date]");?></td>
<td><a href="article-<? echo("$row[article_id]");?>"><? echo("$row[name]");?></a></td>
</tr>

<?
} // end of while statement - getting results from DB
?>
[/php]

Any help would be greatly appreciated :)

adammc

1:34 am on Jun 9, 2007 (gmt 0)

10+ Year Member



i had qutes around my query:
$result = mysql_db_query($db,"$query",$cid);

there appears to be a prob with my limit / order by code too :(

i had to remove this as well ' LIMIT $max_results ORDER BY article_id DESC' to get it to display results.

does anyone have any ideas as to what is wrong with the limit / order by?

adammc

4:59 am on Jun 9, 2007 (gmt 0)

10+ Year Member



i got it sorted by putting the limit at the end of the query statement.

dreamcatcher

6:21 am on Jun 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it sorted. The LIMIT clause does indeed have to be at the end.

dc