Jump to content

[SOLVED] mysql_num_rows(): supplied argument is not a valid MySQL result resource


scarhand

Recommended Posts

I am getting this error and can't understand why. This is in regards to attempting to retreive data from PHPBB tables so that I can display 5 posts as news articles on my main home page.

 

Here is my code:

 

<?php
include 'forumconfig.php';

$query = 'SELECT
		  t.topic_id,
		  t.topic_title,
		  pt.post_text,
		  u.username,
		  u.user_id,
		  t.topic_replies,
		  t.forum_id,
		  t.topic_poster,
		  t.topic_first_post_id,
		  t.topic_status,
		  pt.post_id,
		  p.post_id,
		FROM
		  phpbb_topics AS t,
		  phpbb_users AS u,
		  phpbb_posts_text AS pt,
		  phpbb_posts AS p
		WHERE
		  t.forum_id IN (1) AND
		  t.topic_poster = u.user_id AND
		  t.topic_first_post_id = pt.post_id AND
		  t.topic_first_post_id = p.post_id AND
		  t.topic_status <> 2
		ORDER BY
		  t.topic_time DESC
      LIMIT
		  5';
  
$result = mysql_query($query);

  if (mysql_num_rows($result) == 0)
  {
    echo 'There is currently no news to display.';
  }

  while ($row = mysql_fetch_assoc($result)) 
  {               
    $title = $row['t.topic_title'];
    $news = $row['pt.post_text'];
    $poster = $row['u.username'];
    $topicid = $row['t.topic_id'];
    $comments = $row['t.topic_replies'];

    echo '<div class="headns">' . $title . '</div><br />';
    echo $news . '<br /><br />';
    echo '- ' . $poster . '<br />';
    echo '<a href="forums/viewtopic.php?t=' . $topicid . '">comments (' . $comments . ')</a><br /><br />';
  }?>

 

Now the 'forumconfig.php' file just connects to the database for the phpbb forum, that works fine. For some reason I am getting "mysql_num_rows(): supplied argument is not a valid MySQL result resource", as well as "mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource". I can't seem to figure out why.

 

Any help would be greatly appreciated.

Link to comment
Share on other sites

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.