Jump to content

pulling infomation from a database. simple error


jeppers

Recommended Posts

i am working on a forum script and i am trying to pull some info from a database. but i keep on getting this message

 

"Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\test\discussion\viewforum.php on line 32"

 

i have looked back through my script and can't seem to see any errors but maybe i am missing something silly. hear is my code please have a look as its completely baffled me.

 


$forumsql = "SELECT * FROM forums WHERE id = " . $validforum . ";";
$forumresult = mysql_query($forumsql);
$forumrow = mysql_fetch_assoc($forumresult);

echo "<h2>" . $forumrow['name'] . "</h2>";

echo "<a href='index.php'>" . $config_forumsname . " forums</><br /><br />";
//add a link that allows you to add a new topic to this form

echo "[<a href='newtopic.php?id= " . $validforum . "'>New Topic</a>]";
echo "<br /><br />";

$topicsql = "SELECT MAX (message.date) AS maxdate, 
topics.id AS topicid, topics.*, users.*
FROM messages, topics, users WHERE messages.topic_id
= topic.id AND topics.user_id = user.id AND 
topics.forum_id ORDER BY maxdate DESC;";
$topicresult = mysql_query($topicsql);
$topicnumrows = mysql_num_rows($topicresult); // line 32 this is where the error said it was happening....
if ($topicnumrows == 0) {
	echo "<table width='300px'><tr><td>No Topics!!</td></tr></table>";

 

hopefully you can see where i have went wrong

 

thanks

check the query is correct. You should not continue to process the script if the query produces an error which is what you are doing. You need to handle errors. A simple method is:

 

if(!$result = mysql_query("SELECT ...")) {

  die(mysql_error());

}

@ jeppers,

 

Try this;

 

$topicsql = mysql_query("SELECT MAX (message.date) AS maxdate, 
topics.id AS topicid, topics.*, users.*
FROM messages, topics, users WHERE messages.topic_id
= topic.id AND topics.user_id = user.id AND 
topics.forum_id ORDER BY maxdate DESC") or die (mysql_error());

 

note the "or die mysql_error()); should tell where your error is coming from.

 

I also observe something in your query, why are you terminating immediately after maxdate DESC.

 

Regards

 

 

 

If the query is incorrect the script will terminate. If OK the results of the query are in $forumrow.

Apply to the rest of your logic.

if(!$forumresult = mysql_query($forumsql)) {
die(mysql_error());
exit();
}

$forumrow = mysql_fetch_assoc($forumresult);

$topicsql = "SELECT MAX(messages.date) AS maxdate, 
topics.id AS topicid, topics.*, users.*
FROM messages, topics, users WHERE messages.topic_id
= topics.id AND topics.user_id = users.id AND 
topics.forum_id ORDER BY maxdate DESC;";
if (!$topicresult = mysql_query($topicsql)) {
die(mysql_error());
exit();

 

well i found a few errors so not to bad but i have hit another error report which i have not see before.

 

 

Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

 

i no what it means but where in the code is the issue

 

can you see it

 

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.