takn25 Posted January 30, 2011 Share Posted January 30, 2011 Hi here is my statement <?php $qid=$_GET['qid']; require_once('database_connect.php'); $answer = "SELECT answers.* FROM answers WHERE aid ='$qid'"; $resulta=mysql_query($answer) or die (mysql_error()); while ($rowa=mysql_fetch_assoc($resulta)) { $aid=$rowa['aid']; $answer=$rowa['answer']; $info_rows = mysql_num_rows($resulta); if($info_rows > 0) {echo "$answer";}else {echo "be the first to answer this question";} ;} ?> the IF part is working fine but the else isnt displaying anything at all. Could you kindly tell me, what am i doing wrong and lastly this statement is in a while loop. Quote Link to comment Share on other sites More sharing options...
takn25 Posted January 30, 2011 Author Share Posted January 30, 2011 Figured a different way of going around this thanks. Quote Link to comment Share on other sites More sharing options...
PaulRyan Posted January 30, 2011 Share Posted January 30, 2011 <?PHP if(isSet($_GET['qid'])) { require_once('database_connent.php'); $qid = intval($_GET['qid']); $query = "SELECT answers.* FROM answers WHERE aid = $qid LIMIT 1"; if($doQuery = mysql_query($query)) { // Make sure the query executes if($result = mysql_num_rows($doQuery)) { // Check for returned rows, if exists echo Answer. $aid = $result['aid']; $answer = $result['answer']; echo $answer; } else { echo 'Be the first to answer this question.'; // No rows exist, so question has not been answered } } else { echo 'This query failed [ '.$query.' ]'; // Query has failed, echo it out to see why } } else { echo 'There is no question id set.'; // No qid was set from the URL GET parameter } ?> Try using the code above, it's better formatted and includes some minimal validation and error reporting. Regards, PaulRyan. Quote Link to comment 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.