Jump to content

Drop Down menu Action


Hameed

Recommended Posts

Hi everyone,
I'm developing a system that used in colleges. it allocates sections of courses with certain capacities to rooms of the college that have the same capacity or more.

in one page,I'm using three drop down menus which are: 1.Subject name 2. Section number 3.rooms that have the same capacity of the selected section, when you first select a subject, the sections of that subject drop down menu will be updated via a connection with the database. and when you select a section, the drop down menu of the room with the same capacity will be updated also.
my problem is:
after having the rooms with the same capacity in the third drop down menu, and when i choose one of these rooms, a table of that room is displayed to show the user when this room is available. so that he/she can choose the desired time for that selected section.
can you tell me how to display a table by choosing an option from a drop down menu?

this is the code i'm developing for this, it would be nice if you told me what's wrong with it:

[code]
<?php
$dbservertype='mysql';
$servername='localhost';
// username and password to log onto db server
$dbusername='';
$dbpassword='';
// name of database
$dbname='roomdatabase';
///////////////////////////
//$RoomID = $_REQUEST['Room_ID'];

////////////////////////////////////////
////// DONOT EDIT BELOW  /////////
///////////////////////////////////////
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}

?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>Multiple drop down list box from plus2net</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='dd3Test.php?cat=' + val ;
}
function reload3(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
var val2=form.subcat.options[form.subcat.options.selectedIndex].value;

self.location='dd3.php?cat=' + val + '&cat3=' + val2 ;
}

</script>
</head>

<body>


<?php

///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT Subject_Name FROM section");
///////////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory/////
$cat=$HTTP_GET_VARS['cat']; // This line is added to take care if your global variable is off
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT Section, Students_Number FROM section where Subject_Name = '$cat'");
}else{$quer=mysql_query("SELECT DISTINCT Section, Student_Number FROM section"); }
////////// end of query for second subcategory drop down list box ///////////////////////////
?>
<?php
/////// for Third drop down list we will check if sub category is selected else we will display all the subcategory3/////
$cat3=$HTTP_GET_VARS['cat3']; // This line is added to take care if your global variable is off
if(isset($cat3) and strlen($cat3) > 0){
$quer3=mysql_query("SELECT room_title FROM room_db, section where room_db.capacity = section.student_Number && section.section=$cat3");
}else{$quer3=mysql_query("SELECT DISTINCT room_title FROM room_db"); }
////////// end of query for third subcategory drop down list box ///////////////////////////

echo "query: ". $query1."<br>".$query2."<br>".$query3."<br>";
echo "<form method=post name=f1 action=''>";
//////////        Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) {
if($noticia2[0]==@$cat){echo "<option selected value='$noticia2[0]'>$noticia2[0]</option>"."<BR>";}
else{echo  "<option value='$noticia2[0]'>$noticia2[0]</option>";}
}
echo "</select>";
//////////////////  This will end the first drop down list ///////////

//////////        Starting of second drop downlist /////////
echo "<select name='subcat' onchange=\"reload3(this.form)\"><option value=''>Select one</option>";
while($sectionD = mysql_fetch_array($quer)) {
if($sectionD[0]==@$cat3){echo "<option selected value='$sectionD[0]'>$sectionD[0]</option>"."<BR>";}
else{echo  "<option value='$sectionD[0]'>$sectionD[0]</option>";}
}
echo "</select>";
//////////////////  This will end the second drop down list ///////////


//////////        Starting of third drop downlist /////////
echo "<select name='subcat3' ><option value=''>Select one</option>";
while($roomD = mysql_fetch_array($quer3)) {
    if($roomD[0]==@$cat3){echo  "<option selected value='$roomD[0]'>$roomD[0]</option>";
    //else(echo "<option value='$roomD[0]'>$roomD[0]</option>";}
}}

echo "</select>";


//////////////////  This will end the third drop down list ///////////
////////////////////////////////////////////////////////////////////////////////////////////////////////

$time_max = '16';
$time_min = '8';
$days_array = array('UT','MW','R');
?>


<table border=1>
<tr bgcolor=silver>
<td>
Room/Time
</td>
<?
for ($i = $time_min; $i <= $time_max; $i+=2)
{?>
  <td><?=$i?> - <?=$i+2?></td>
<?}
?>
</tr>
<?
$query = "SELECT * FROM section";

$result = mysql_query($query);//or die(mysql_error());

$num_results = mysql_num_rows($result);
$row = mysql_fetch_array($result);
$i = 0;

//echo "I am here <br>";

while($i<$num_results){
  for($j=0; $j<3; $j++)
  {
    $time_counter = $time_min;

  // echo "<br>Room:  ".$row[roomID]."<br><br>";
    ?>
    <tr>
      <td><?=$row['Room_Title']?>&nbsp;<?=$days_array[$j]?></td>
    <?
while($time_counter <= $time_max)
{

//echo "time: ".$time_counter." ";
$query2 = "SELECT * FROM section where days !='".$days_array[$j]."' AND room ='".$roomD[0]."' AND class_Time !='".$time_counter."';";

//    echo  "Query is ". $query2;

$result2 = mysql_query($query2)or die(mysql_error());

$num_results2 = mysql_num_rows($result2);
$row2 = mysql_fetch_array($result2);

    $b= '$days_array[$j].$time_counter';

    if ($result2){
        while ($row2 = mysql_fetch_array($result2)){
              echo "<td width='25%'><input type=checkbox name=box[] value=$b></td> ";

        }
        echo $row2['section_ID'] . "I am here <br>" . $row2[section_ID];
  /////////display
//echo " ".$row2[courseTitle]."  ".$row2[secID]."<br>";
// $time_counter+=2;
    }
    }

  ?>
  </tr>
  <?
}
  $i++;
  $row = mysql_fetch_array($result);
  //$time_counter+=2;

}
echo "</form>";
?>

</table>
</body>
</html>
[/code]
Regards

Hameed ;D
Link to comment
https://forums.phpfreaks.com/topic/31402-drop-down-menu-action/
Share on other sites

Maybe I am way off here (because your post was a bit confusing, and an whole lot of code...use the code brackets next time) I think you know how to get the results but just want to know how to display those results once you get them in a sort of "dynamic" way (since you report no errors, I can assume your code works)??? If that's the case, I would create hidden <div>'s with the third dropdown results then when a user clicks an option in the third menu, use JS to change the div style to "block" to magically diaplay the table. This would work for each of the third dropdown options if you dynamically create the <div>'s given your DB results.

Google "hidden div javascript" to figure out how to do this.

I'm probably way off on this solution, but I though I would give it a try.
Link to comment
https://forums.phpfreaks.com/topic/31402-drop-down-menu-action/#findComment-145407
Share on other sites

Thanks, i did search about it and this is what I've found:[url=http://64.233.183.104/search?q=cache:8PkMbo8bmaUJ:www.netlobo.com/div_hiding.html+hidden+div+javascript&hl=en&ct=clnk&cd=2&client=firefox-a]http://64.233.183.104/search?q=cache:8PkMbo8bmaUJ:www.netlobo.com/div_hiding.html+hidden+div+javascript&hl=en&ct=clnk&cd=2&client=firefox-a[/url]
but how can I implement this using PHP coder?

Hameed ;D
Link to comment
https://forums.phpfreaks.com/topic/31402-drop-down-menu-action/#findComment-145680
Share on other sites

I have found that the best way to tackle a problem like this is to break it down into pieces and them implement each piece until I get the whole thing working.  If you haven't already solved this, look into implementing an Ajax solution.  In this kind of solution you use Javascript to send an XML query to the server and then process the response.  You can just send the class and room information then display the availability table using the result from the Ajax call.  I find that this works similar to event handlers in Java and C++, very cool stuff.  Hope this helps.
Link to comment
https://forums.phpfreaks.com/topic/31402-drop-down-menu-action/#findComment-145712
Share on other sites

I'm using PHP not XML, I would really appreciate it if you could try my code and tell me what am I supposed to do, I attached my database, can anyone try it please! I'm beginner in PHP so I'm not aware of some terms like div and ajax.

Regards,

Hameed

[attachment deleted by admin]
Link to comment
https://forums.phpfreaks.com/topic/31402-drop-down-menu-action/#findComment-145731
Share on other sites

Archived

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

×
×
  • 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.