Jump to content

Archived

This topic is now archived and is closed to further replies.

rsammy

help with php list box

Recommended Posts

i am working on a php app. i need to populate a list box(drop down) with three values(not from db) like 'ALL', 'ACTIVE' and "INACTIVE'.

when 'ACTIVE' is chosen from the list box, i need to check one table in the db and get all the info from the table based on a certain criteria. if INACTIVE is chosen, then another table is searched and infor from that table needs to be displayed. ALL displays values from both tables.

Lemme make it clearer:

I have two tables: admission and admit_status. the admission table has a field called discharge_date. as long as the patient is admitted, this field shows '00-00'0000' as the date. it is updated with the date when the patient is discharged. while this date is being updated, the patients info(such as, location, reason, room_no, admit date, etc.) is deleted from theadmit_status table.

I am checking on a patient activity summary report. in this report, i need to see all those patients who are either "ACTIVE' or "INACTIVE'. ACTIVE means the patient is still active in the hospital(admitted state and his discharge_date in the admission table is still '0000-00-00'.

If the I choose INACTIVE from the drop down, the those patients who have been discharged and not active (or admitted in the hospital) - whose info has been deleted from the admit_status table - need to be displayed.

ALL -should display all patients irrespective of their status.

hope i am clear here. any help will be appreciated. THANKS

Share this post


Link to post
Share on other sites
Well if you're looking to have it done automatically you're going to need to use AJAX which can do your queries without refreshing the page.  It's a lot more to learn and it takes time and well, I'm angry at it right now.

If you want a drop down with your 3 options and a submit button, I may be able to help.

If this were me though, I would change 'all','active','inactive' fields to '0','1','2' for that inner nerd in me.  The rest is fairly simple.

[code]
<form action="results.php" method="post">
  <select name="patient_status" size="3">
    <option selected="selected">Patient status</option>
    <option value="0">All</option>
    <option value="1">Active</option>
    <option value="2">Inactive</option>
  </select>
  <input type="submit" value="Fetch" />
</form>

<?php
if ($_POST['patient_status']) {
  $checkStatus = mysql_query("SELECT field1, field2 FROM table WHERE status = $_POST[patient_status]") or die (mysql_error());
}

if (mysql_num_rows($checkStatus) == 0) {
  // nothing was returned, fail
} else {
  while ($patient = mysql_fetch_array($checkStatus)) {
    // list patients
  }

?>
[/code]

That's the basics of it all but it should get you started or at the very least, occupied.  I use Adodb so my basic mySQL is kind of rusty, sorry for any errors there.

Share this post


Link to post
Share on other sites

×

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.