Jump to content

How to select one row from query result


boorama

Recommended Posts

Hi all,

 

I am new to php and MySql. I am designing a booking system.

 

to book an appointment a unique Id is entered together with the location of the appointment.

 

once the button is clicked a table of available slots is displayed.

 

my problem is how to select one slot. I was thinking to have a checkbox column, but not sure how to do that with the result of the query.

 

another thing is once I click the button, the unique Id and location disappear. how can I keep them displayed once the form is posted.

 

I hope I make sense.

 

below is the code and your help is highly appreciated.

 

<?php

include("db.php"); // connection to database
include_once ('hh.php');


   echo "<h2>Please fill booking details below</h2>";
?>
           
        

               <form action= '<?php echo($PHP_SELF); ?>' method='POST' name='bf'>
  <p> </p>

  <table width='50%' border='0' align='center'cellpadding='4' cellspacing='0'>
    <tr>
      <td width='29%'><font face='Copperplate Gothic Light'>NHS Number</font></td>
      <td width='68%'><input name='nhs' type='text' id='nhs'></td>
    </tr>
    <tr>
      <td><font face='Copperplate Gothic Light'>Select hospital</font></td>
      <td><select name='hosp'>
      <option></option>
	<option value='Hammersmith Hospital'>Hammersmith Hospital</option>
	<option value='Charing Cross Hospital'>Charing Cross Hospital</option>
	<option value='Selly Oak Hospital'>Selly Oak Hospital</option>
	</select></td>
    </tr>
    <tr>
      <td><font face='Copperplate Gothic Light'>find appointment</font></td>
      <td><input type='submit' name="fapp" value='GO'></td>
    </tr>
  </table>
     
</form>


<?php

if($_POST['fapp']){

if((!$_POST['nhs']) || (!$_POST['hosp'])){

         
echo "<strong><font color = red>Please enter NHS number and select a Hospital! </font><br />";
          }else{

      $sql = mysql_query("SELECT * FROM patient WHERE nhs_num='{$_POST['nhs']}' ");    
      $check = mysql_num_rows($sql);
if($check > 0){

while($row = mysql_fetch_array($sql)){



                             $query = "SELECT 
          
	              h.name,
	              h.location,
	              h.address,
                                                   

DATE_FORMAT(t.app_date, '%a,%e %M, %Y, %l:%i%p') AS newdate 

                    FROM hospital h, time_slot t
                  
                    WHERE   t.hospital_id = h.hospital_id
                     AND h.name = '{$_POST['hosp']}'
                     AND    t.slot_ava = 'Y' ";
                    
$result = @mysql_query ($query);
// store the record

echo '<br />';



echo '<table border="1" align="center" cellspacing="2" cellpadding="2"> 
          
     <td align="left"><b>Hospital</b></td>
   <td align="left"><b>Location</b></td>
<td align="left"><b>Address</b></td>
<td align="left"><b>Appointment Date & Time</b></td>


             
                </tr>';

// print record

$bg = '#eeeeee';
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
	$bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee');	
	echo '<tr bgcolor="', $bg, '"><td align="left">', stripslashes($row[0]), '</td><td align="left">', $row[1], '</td>
                                <td align="left">', $row[2], '</td>
                                <td align="left">', $row[3], '</td>
                     
                            

                            
                                </tr>';
}

echo '</table>';
mysql_free_result ($result);	
}

}else {

echo "<strong><font color = red>The NHS number your entered is incorrect!<br />
Please try again! </font><br />";

}
}
}
          
mysql_close();   

include_once ('ff.php');
?>

Link to comment
Share on other sites

I am not sure what you mean by: "I want the selection to be from the query result not initially."

 

A hidden input is used in forms to pass a value that the user doesn't see:

 

For example:

 

<input type=hidden name=id value="<?=$id?>">

 

When this is posted it will post your ID.

 

 

Link to comment
Share on other sites

Thanks again frost for replyin.

 

I want to book an appointment.

 

once the button is clicked to find an appointment the following query is executed:

 

$sql = mysql_query("SELECT * FROM patient WHERE nhs_num='{$_POST['nhs']}' ");   

      $check = mysql_num_rows($sql);

if($check > 0){

 

while($row = mysql_fetch_array($sql)){

 

 

 

                            $query = "SELECT

         

              h.name,

              h.location,

              h.address,

                                                 

 

DATE_FORMAT(t.app_date, '%a,%e %M, %Y, %l:%i%p') AS newdate

 

                    FROM hospital h, time_slot t

                 

                    WHERE  t.hospital_id = h.hospital_id

                    AND h.name = '{$_POST['hosp']}'

                    AND    t.slot_ava = 'Y' ";

 

the result of this query is the the available appointments.

 

I want to select one of them to be booked. but not sure how to do that.

 

I hope its clearer now.

 

Link to comment
Share on other sites

Ok so you are outputting all of the available appointments right?

 

Add a radio button to each appointment and then when the user picks an apointment you can book that appointment? The radio button could have the appointments unique ID and you could post that info to do the booking.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.