Jump to content

check query whether executed or not


gaya

Recommended Posts

Please explain in more detail. If you want to know whether the query data is arriving at your script correctly, simply write this: var_dump($_GET); Try it with no other code in the script to make sure an error isn't messing things up.

Link to comment
Share on other sites

No no not like that. my concept writing exams in online & if a student had already attended the question he should not able to write again. So i'd set some images,as not_answered,review_answer,answered. By checking the flag values the images will get changed.the following is my code. In that i've to set the not_answered image as default. But i cann't. Please tell me wat i did wrong in that.

$query2="select flag from tablename where id ='$Id' && no ='$no'";  $res=mysql_query($query2);   if(!$res)  {  echo "<a href='a.php?no=$no∂=$part&qpid=$qpid&board=$board&subject=$subject&StudentId=$StudentId&totalrows=$totalRows1'><img src='img/not_answered.png'></a>";  }   else  {  while($rw = mysql_fetch_array($res)) {  $flag1=$rw['flag'];   if($flag1==1)  {   echo "<a href='a.php?no=$no∂=$part&qpid=$qpid&board=$board&subject=$subject&StudentId=$StudentId&totalrows=$totalRows1'><img src='img/review_answer.png'></a>";  }  else if($flag1==2)  {   echo "<a href='a.php?no=$no∂=$part&qpid=$qpid&board=$board&subject=$subject&StudentId=$StudentId&totalrows=$totalRows1'><img src='img/answered.png'></a>";  }  else  {  echo "<a href='aphp?no=$no∂=$part&qpid=$qpid&board=$board&subject=$subject&StudentId=$StudentId&totalrows=$totalRows1'><img src='img/not_answered.png'></a>";  }  }} 

Edited by gaya
Link to comment
Share on other sites

You can use the mysql_num_rows(); function to check if the query returns a row which in your query I believe should return 1 or none (0). For the if statement, you can have something like:

$numRows = mysql_num_rows($res); if($numRows == 0) // for not answered image{     echo "<a href='a.php?no=$no∂=$part&qpid=$qpid&board=$board&subject=$subject&StudentId=$StudentId&totalrows=$totalRows1'><img src='img/not_answered.png'></a>";}

  • Like 1
Link to comment
Share on other sites

Thanks Don. By using the code i get the result.

$numRows = mysql_num_rows($res);if($numRows == 0) // for not answered image{	 echo "<a href='a.php?no=$no∂=$part&qpid=$qpid&board=$board&subject=$subject&StudentId=$StudentId&totalrows=$totalRows1'><img src='img/not_answered.png'></a>";}

Thanks again.

Link to comment
Share on other sites

Now i've to do another thing. i.e.) I've a submit button and review button. By clicking submit button the answer get saved and the not answered image will change to answered image. But by clicking the review button the written answers should get save in a txt file and then the not answered image is get updated to review _answer image. How shall i do this. Any ideas please tell me.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...