Jump to content

[SOLVED] Query Was Empty Error PLEASE HELP!


GraphiX

Recommended Posts

When I execute the following code, there is an error before the table is echoed reading "Query was Empty", also no data is diaplayed in the table even though there are records in the database.

 

       
        } else {
            $sql2 = "SELECT * FROM `forum_topics` WHERE `cid`='" . $row['id'] . "'";
            $res2 = mysql_query($sql2) or die(mysql_error());
            if (mysql_num_rows($res2) == 0) {
                echo "There no topics to display in this forum. <a href="./index.php?act=create&id=".$row['id']."">Click Here</a> to create one. ";
            } else {
                echo "<table border="0" cellspacing="3" cellpadding"3"> ";
                echo "<tr align="center"><td>Title</td><td>User</td><td>Date</td><td>Replies</td></tr> ";
                  while ($row2 = mysql_fetch_assoc($res2)) {
                   #$sql3 = "count(*) AS `num_replies` FROM `forum_replies WHERE `tid`='".$row2['id']."'";
                    #$res3 = mysql_query($sql3) or die(mysql_error());
                    #$row3 = mysql_fetch_assoc($res3);
                    echo "<tr><td><a href="index.php?act=topic&id=".$row2['id'].">".s($row2['title'])."</a></td><td>".uid($row2['uid'])."</td><td>".$row2['date']."</td><td>".$row3['num_replies'] . "</td></tr> ";
                }
                echo "</table> ";
            }
        }
    }
} else {
    echo "Please supply a catergory ID.";
}

?>

 

Hope you Can Help Me!

 

GraphiX

Link to comment
Share on other sites

Well, one problem I do see with your code, as seen with syntax highlighting... Things like:

echo "There no topics to display in this forum. <a href="./index.php?act=create&id=".$row['id']."">Click Here</a> to create one. ";

 

You need to either use single quotes (I recommend) or escape the quotes

echo 'There no topics to display in this forum. <a href="./index.php?act=create&id='.$row['id'].'">Click Here</a> to create one. ';

 

See the difference above? You have that all over the place.

Link to comment
Share on other sites

Well, one problem I do see with your code, as seen with syntax highlighting... Things like:

echo "There no topics to display in this forum. <a href="./index.php?act=create&id=".$row['id']."">Click Here</a> to create one. ";

 

You need to either use single quotes (I recommend) or escape the quotes

echo 'There no topics to display in this forum. <a href="./index.php?act=create&id='.$row['id'].'">Click Here</a> to create one. ';

 

See the difference above? You have that all over the place.

 

I did escape my tags but when I posted the Board stripped the slashes on the code.

Link to comment
Share on other sites

Well, you also changed your code after I posted. However, the forum shouldn't be strip slashes from your posts.

 

Nonetheless, make sure they are in there. Next step - what does the query echo out to? Can you run it in something like PHPMyAdmin?

$sql2 = "SELECT * FROM `forum_topics` WHERE `cid`='" . $row['id'] . "'";
echo $sql2;

 

 

Try replacing the code you posted with:

} else {
            $sql2 = "SELECT * FROM `forum_topics` WHERE `cid`='" . $row['id'] . "'";
		echo $sql2; // Let's echo and see what it shows.
            $res2 = mysql_query($sql2) or die('Uh-oh, mysql error: '.mysql_error());
            if (mysql_num_rows($res2) == 0) {
                echo 'There no topics to display in this forum. <a href="./index.php?act=create&id='.$row['id'].'">Click Here</a> to create one. ';
            } else {
                echo '<table border="0" cellspacing="3" cellpadding"3"> ';
                echo '<tr align="center"><td>Title</td><td>User</td><td>Date</td><td>Replies</td></tr> ';
                  while ($row2 = mysql_fetch_assoc($res2)) {
                   #$sql3 = "count(*) AS `num_replies` FROM `forum_replies WHERE `tid`='".$row2['id']."'";
                    #$res3 = mysql_query($sql3) or die(mysql_error());
                    #$row3 = mysql_fetch_assoc($res3);
                    echo '<tr><td><a href="index.php?act=topic&id='.$row2['id'].'">'.s($row2['title']).'</a></td><td>'.uid($row2['uid']).'</td><td>'.$row2['date'].'</td><td>'.$row3['num_replies'] . '</td></tr> ';
                }
                echo '</table> ';
            }
        }
} else {
    echo 'Please supply a catergory ID.';
}

Link to comment
Share on other sites

Returns This:

 

SELECT * FROM `forum_topics` WHERE `cid`='7'Query was empty [table][tr][td][table][tr][td]Title[/td][td]User[/td][td]Date[/td][td]Replies[/td][/tr][/table][/t]
[/td][/tr][/table]

 

Sorry if i'm a bit clueless but this bewilders me.

Link to comment
Share on other sites

Change:

$sql2 = "SELECT * FROM `forum_topics` WHERE `cid`='" . $row['id'] . "'";
		echo $sql2; // Let's echo and see what it shows.
            $res2 = mysql_query($sql2) or die('Uh-oh, mysql error: '.mysql_error());

to

$res2 = mysql_query("SELECT * FROM `forum_topics` WHERE `cid`='" . $row['id'] . "'") or die('Uh-oh, mysql error: '.mysql_error());

Link to comment
Share on other sites

When the query (With the varible set to 7) was entered into PHPmyAdmin it returned this

 

SELECT  *

FROM  `forum_topics`

WHERE  `cid`  =  '7';

 

And the result it should have.

 

I don't see why it won't work in my Script.

 

 

I know it is kind of stupid, the code looks fine so I am throwing this out there:

 

Are you sure you are connecting to the right database?

Link to comment
Share on other sites

When the query (With the varible set to 7) was entered into PHPmyAdmin it returned this

 

SELECT  *

FROM  `forum_topics`

WHERE  `cid`  =  '7';

 

And the result it should have.

 

I don't see why it won't work in my Script.

 

 

I know it is kind of stupid, the code looks fine so I am throwing this out there:

 

Are you sure you are connecting to the right database?

 

Yeah, i'm pretty sure. I googled around a bit and most of these have ended up unsolved.

Link to comment
Share on other sites

Well, now from where I see it this is pretty much hopeless, now that the SQl is actually in the mysql_query function, there are no variables to lose. I know the SQL syntax is ok, because PHPmyAdmin parsed it with no errors. the only thing that could be affecting it is the PHP syntax on the actual statement.

 

Any Suggestions?

 

(I'm off now for tonight, be back on tommorow.)

 

 

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.