Jump to content

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);

not sure what the problem it but the error which is poping up is still

 

 

FUNCTION forum.MAX does not exist

 

so the first query is correct but the error is within the second query. all around the MAX function

 

have you any ideas.

$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

 

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.