Jump to content

Trouble With getting a variable from database!


id

Recommended Posts

OK, so im working on a mini forum board, and i ran into some problems...

 

On my view_topic.php file i want the user to be able to see his post_count... which is simple because all i have to do is do a

mysql_query and a mysql_fetch_array.

, which works fine.

 

However i am getting a warning... "Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in C:\wamp\www\EmporaTech_Site\forum\view_topic.php on line 40"..

 

<?php
$id         = isset($_GET['id']) ? $_GET['id']: '';
$result     = mysql_query("SELECT * FROM forum_question WHERE id='$id'");

while($row = mysql_fetch_array($result))
{
$username = isset($row['username'])  ? $row['username']  : '';
$post_count = mysql_query("SELECT * FROM members WHERE username='$username'");
while($row_1 = mysql_fetch_array($post_count))
{
$post_count = $row_1['post_count'];	
$topic    = isset($row['topic'])     ? $row['topic']     : '';
$detail   = isset($row['detail'])    ? $row['detail']    : '';
$view     = isset($row['view'])      ? $row['view']      : '';
$reply    = isset($row['replies'])   ? $row['replies']   : '';
$date     = isset($row['date_time']) ? $row['date_time'] : '';
?>

 

PS... I have a curly brace for the while statement further down in my script, so that's not the issue.

That error comes from a failed query.  Mysql_query returns false when the query fails.  False, as you may know, is not a mysql result set resource.  That's where the error comes from.

 

If your mysql_query returns false, echo mysql_error().  That will show you why it's failing.

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.