1

my code doesnt seem to work.. the radio buttons appear but nothing beside them .. it seems as if the mysql_fetch_row is not working for some reason as i have played about with the code and replaced $qnumber to a value manually and tested it however nothing appeared. could someone please advise what is wrong? cheers ps. i am new at this.

this is my code.

<?php

include 'dbyear2.php';

$qnumber = ($_REQUEST['uqn']); // obtain question number from URL

$find = mysqli_query($condbyear2, "SELECT * FROM Renal WHERE UQN='$qnumber'");

 while($retrieve=mysqli_fetch_row($find));
 {

      $question = $retrieve['question'];
      $a = $retrieve['MCQ_A']; 
       $b = $retrieve['MCQ_B'];
      $c = $retrieve['MCQ_C'];
         $d = $retrieve['MCQ_D'];
      $e = $retrieve['MCQ_E'];
     $answer = $retrieve['answer'];
       $correct = $retrieve['MCQ_correct'];


       }




      ?>


        <form action='check.php' method='POST'>  

    <table> 

  <tr><td></td><td></td></tr>
   <tr></tr>
        <tr><td><input type='radio' name='group1' value='A' /></td><td> <?php echo $a; ?></td></tr>
       <tr><td><input type='radio' name='group1' value='B' /></td><td> <?php echo $b; ?></td></tr>
         <tr><td><input type='radio' name='group1' value='C' /></td><td> <?php echo $c; ?></td></tr>
      <tr><td><input type='radio' name='group1' value='D' /></td><td> <?php echo $d; ?></td></tr>
       <tr><td><input type='radio' name='group1' value='E' /></td><td> <?php echo $e; ?></td></tr> 
   <tr>

      <?php 

     // sending the retrieved information from MYSQL via POST for use in check.php file

    $qnumber;
  $a;
   $b;
     $c;
  $d;
    $e;
  $answer;
    $correct;


   ?></tr>
         <tr><td><input type="submit" value="Submit"></td></tr>





     </table>

        </form>

1 Answer 1

2

1) Remove the ; at the end of the while statement

2) mysqli_fetch_row returns an enumerated array. What you require is an associative array so you should use mysql_fetch_assoc or mysqli_fetch_array instead.

while($retrieve=mysqli_fetch_assoc($find))
{
....
Sign up to request clarification or add additional context in comments.

5 Comments

Check whether $a .... $e are set. If not check whether any rows are being returned with mysqli_num_rows(). Also, have you tried running this query with the manual $qnumber in a mysql console or phpmyadmin?
$a ....$e are not set. i tried to echo them outside teh form and it didnt work. no rows are being returned with mysqli_num_rows(). i used phpmyadmin to run the mysql query and it found the row with no problems.
apologies. it has found the row using mysqli_num_rows(). evyerthing else written above is correct though
That took a while. Further reading php.net/manual/en/class.mysqli-result.php
thank you for your help. i have found out why it's not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.