mysql - how to know when database became empty in php -
i makin quiz in php , mysql . fetching questions database, suppose if don't know no of questions in datbase. want code fetch data till questions not over, don't no of questions there . condtion applicable . code fetching data .
<?php function ravi($qid=null) { $con = mysql_connect('localhost', 'root', '') or die(mysql_error()); $db = mysql_select_db('quiz', $con) or die(mysql_error()); $q="select * question qno=$qid"; $rq=mysql_query($q,$con); if(!$rq) { echo " sql query faiiled work "; } else { while ($sub_row=mysql_fetch_array($rq)) { $id=$sub_row["qno"]; $question=$sub_row["question"]; $option1=$sub_row["option1"]; $option2=$sub_row["option2"]; $option3=$sub_row["option3"]; $option4=$sub_row["option4"]; echo "<h5>q".$id." : ".$question."</br></h5>"; echo"</br> <br> <h4><input type= radio id='1' name=\"{$id}\" value=\"{$option1}\">$option1</h4> </br> <h4><input type= radio id='2' name=\"{$id}\" value=\"{$option2}\">$option2</h4> </br> <h4><input type= radio id='3' name=\"{$id}\" value=\"{$option3}\">$option3</h4> </br> <h4><input type= radio id='4' name=\"{$id}\" value=\"{$option4}\">$option4</h4> </br></br>"; } }} ?>
if (mysql_num_rows($rq) == 0) { echo "database empty."; }
but should stop using mysql_*
has been said in comments.
Comments
Post a Comment