GraphiX Posted January 29, 2009 Share Posted January 29, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/ Share on other sites More sharing options...
GraphiX Posted January 29, 2009 Author Share Posted January 29, 2009 I belive it was something to do with the query to the query variable not being recognised by the mysql_query fucnction but I can'tsee anything wrong with either bit of code... Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-749972 Share on other sites More sharing options...
Philip Posted January 29, 2009 Share Posted January 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-749978 Share on other sites More sharing options...
GraphiX Posted January 29, 2009 Author Share Posted January 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-749989 Share on other sites More sharing options...
Philip Posted January 29, 2009 Share Posted January 29, 2009 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.'; } Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-750008 Share on other sites More sharing options...
GraphiX Posted January 29, 2009 Author Share Posted January 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-750017 Share on other sites More sharing options...
Philip Posted January 29, 2009 Share Posted January 29, 2009 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()); Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-750020 Share on other sites More sharing options...
GraphiX Posted January 29, 2009 Author Share Posted January 29, 2009 It's still returning Query is Empty", it has never done this before Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-750023 Share on other sites More sharing options...
Philip Posted January 29, 2009 Share Posted January 29, 2009 When you run it in something like PHPMyAdmin, what does it do? Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-750025 Share on other sites More sharing options...
GraphiX Posted January 29, 2009 Author Share Posted January 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-750042 Share on other sites More sharing options...
premiso Posted January 29, 2009 Share Posted January 29, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-750047 Share on other sites More sharing options...
GraphiX Posted January 29, 2009 Author Share Posted January 29, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-750063 Share on other sites More sharing options...
Philip Posted January 29, 2009 Share Posted January 29, 2009 Try running a different query there, like just "SELECT * FROM `forum_topics` LIMIT 5" and see if it returns anything. Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-750072 Share on other sites More sharing options...
GraphiX Posted January 29, 2009 Author Share Posted January 29, 2009 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.) Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-750085 Share on other sites More sharing options...
GraphiX Posted January 30, 2009 Author Share Posted January 30, 2009 Just Solved this, it fas an error in my functions file, SILLY ME!!! Thanks for all your help GraphiX Quote Link to comment https://forums.phpfreaks.com/topic/143018-solved-query-was-empty-error-please-help/#findComment-750981 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.