Jump to content

Cant Read from DB in the Drop Menu Only


Teefa

Recommended Posts

hi all , 

 

i want to ask a silly question , im not an experienced web developer 

this is my code 

 

<?php
include "/connect_to_db.php";
$options="";
$options2="";
$options3="";
$options4="";
$dt=array();
global $date;
global $hour;
 
$sql=mysql_query("select Date from Student_Name order by Date "); //where Hour=$hour and Date='$date'
while($rows=mysql_fetch_array($sql)):
$date1=$rows['Date'];
$options.="<OPTION VALUE=\"$date1\">".$date1.'</option>';
endwhile;
?>
 
<form method="post">
Date
<SELECT name="date1">
<? if($_POST['date1']) { $date=$_POST["date1"]; } else { $date='Date';} ?>  
<OPTION VALUE=<?=$date?>><?echo $date ;?>
<?=$options?>
<? $date=$_POST["date1"]; ?> 
</SELECT>
<? 
$sql=mysql_query("select Hour  from Student_Names order by Hour");
while($rows=mysql_fetch_array($sql)):
$hour1=$rows['Hour']; 
$options2.="<OPTION VALUE=\"$hour1\">".$hour1.'</option>';
endwhile;
?>
Hour
<SELECT name="hour1">
<? if($_POST['hour1']) { $hour=$_POST["hour1"]; } else { $hour='Hour';} ?>  
<OPTION VALUE=<?=$hour?>><? echo $hour ;?>
<?=$options2?> 
<? $hour=$_POST["hour1"]; ?>
</SELECT>
 
Link to comment
Share on other sites

there is no data displayed for the variable date one , it was working on the last version but now nothing appear in the drop menu ( empty drop menu) 

at the top when we echo date one it got an array but nothing in drop menu please help 

Link to comment
Share on other sites

if just one of your queries is not working, it's because you are using two different table names. one is Student_Name, the other is Student_Names. you need to ALWAYS test if a query worked or failed before you try to use the data that query was expected to return. if your code had some error checking logic in it, you would have already known that the table name in one of the queries is (probably) not correct.

 

your code is all over the place with things that, in the context of the posted code, don't work or are not needed. you have variables defined, but not used; variables used but not defined; global statements that don't do anything unless inside of a function and even there they should not be used;

 

your table name, which ever one is correct, should hold student name information. why do you have date and hour fields in that table?

Link to comment
Share on other sites

if just one of your queries is not working, it's because you are using two different table names. one is Student_Name, the other is Student_Names. you need to ALWAYS test if a query worked or failed before you try to use the data that query was expected to return. if your code had some error checking logic in it, you would have already known that the table name in one of the queries is (probably) not correct.

 

your code is all over the place with things that, in the context of the posted code, don't work or are not needed. you have variables defined, but not used; variables used but not defined; global statements that don't do anything unless inside of a function and even there they should not be used;

 

your table name, which ever one is correct, should hold student name information. why do you have date and hour fields in that table?

thnx alot , but ive changed my original table names writing this post  , but sure ive checked it in my original script 

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.