boon_chong Posted November 17, 2006 Share Posted November 17, 2006 here is my coding, what i want is, to list out the date from a mysql table in the list box, and when i click retrieve button, it will show the entire record. please somebody help me to figure out... thanks...<html><head><body><?include("8_dbconnect.php");$query = "select date from employee";$result = mysql_query($query);$num_results = mysql_num_rows($result);?><form name ="date" method="post" action="employeeEdit.php"<select name= "date[]"><?for ($i=0; $i <$num_results; $i++){$row = mysql_fetch_array($result);print '<OPTION VALUE="';print $row['date'];print '">';print $row['date'];print '</OPTION>';}?></select><input type = "submit" value = "Retrieve"></form></body></html> Link to comment https://forums.phpfreaks.com/topic/27539-how-to-retrieve-mysql-to-a-list-box/ Share on other sites More sharing options...
The Little Guy Posted November 17, 2006 Share Posted November 17, 2006 [code]<html><head><body><?phpinclude("8_dbconnect.php");$query = "select date from employee";$result = mysql_query($query);?><form name="date" method="post" action="employeeEdit.php"><select name= "date[]"><?phpwhile($row = mysql_fetch_array($result)){ echo '<OPTION VALUE="'.$row['date'].'">'.$row['date'].'</OPTION>';}?></select><input type= "submit" value= "Retrieve"></form></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/27539-how-to-retrieve-mysql-to-a-list-box/#findComment-126003 Share on other sites More sharing options...
boon_chong Posted November 17, 2006 Author Share Posted November 17, 2006 But when I click the 'retrieve' button the result is not come out,why? only the table layout is showing. Here is the employeeEdit.php<? if($date) { include("8_dbconnect.php"); print("<table width=\"755\" border=\"1\" cellpadding=\"3\">\n"); print("<tr><td><H5>No</H5></td>");print("<td width=\"180\"><H5>Item No</H5></td>");print("<td width=\"180\"><H5>Item Description</H5></td>");print("<td width=\"90\"><H5>Product Group</H5></td>");print("<td width=\"90\"><H5>Sales Type</H5></td>");print("<td width=\"90\"><H5>Original Price</H5></td>");print("<td><H5>Discount</H5></td>");print("<td width=\"110\"><H5>Net Price</H5></td>");print("<td><H5>Quantity</H5></td>");print("<td width=\"60\"><H5>Total</H5></td>");//print("<td><H5>Grand</H5></td>");$query = "select * from employee where employee.date='$date'"; $mysql_result = mysql_query($query, $mysql_link);while($row = mysql_fetch_row($mysql_result)) { print("<h3></h3>"); print("<form action=\"8_storeAdminMenu.php\">"); print("<table width=\"760\" border=\"0\" cellpadding=\"3\">\n");printf("<tr><td width=\"15\">%s</td>",$row[0]);printf("<td width=\"70\">%s</td>", $row[1]);printf("<td width=\"90\">%s</td>", $row[2]);printf("<td width=\"50\">%s</td>",$row[3]);printf("<td width=\"45\">%s</td>",$row[4]);printf("<td width=\"50\" align=right>%s</td>",$row[5]);printf("<td width=\"40\" align=right>%s</td>",$row[6]);printf("<td width=\"43\" align=right>%s</td>", $row[7]);printf("<td width=\"35\" align=right>%s</td>",$row[8]);printf("<td width=\"35\" align=right>%s</td>",$row[9]); print("<input type=\"hidden\" name=\"nav\" value=\"Daily Sales\">"); print("<input type=\"hidden\" name=\"action\" value=\"Edit\">"); printf("<input type=\"hidden\" name=\"no\" value=\"%s\">", $date); print("</table>"); print("</form>"); }$result = mysql_query("SELECT sum(total) FROM employee where employee.date='$date'");echo "Grand Total: ";echo mysql_result($result,0); include("8_dbdisconnect.php"); }?> Link to comment https://forums.phpfreaks.com/topic/27539-how-to-retrieve-mysql-to-a-list-box/#findComment-126021 Share on other sites More sharing options...
The Little Guy Posted November 17, 2006 Share Posted November 17, 2006 Try and change:- [b]if($date)[/b]- [b]$query = "select * from employee where employee.date='$date'";[/b]To:- [b]if($_POST['date'])[/b]- [b]$query = "select * from employee where employee.date='$_POST[date]'";[/b] Link to comment https://forums.phpfreaks.com/topic/27539-how-to-retrieve-mysql-to-a-list-box/#findComment-126022 Share on other sites More sharing options...
boon_chong Posted November 17, 2006 Author Share Posted November 17, 2006 After I change the code it is still the same.<? if($_POST['date']) { include("8_dbconnect.php"); print("<table width=\"755\" border=\"1\" cellpadding=\"3\">\n"); print("<tr><td><H5>No</H5></td>");print("<td width=\"180\"><H5>Item No</H5></td>");print("<td width=\"180\"><H5>Item Description</H5></td>");print("<td width=\"90\"><H5>Product Group</H5></td>");print("<td width=\"90\"><H5>Sales Type</H5></td>");print("<td width=\"90\"><H5>Original Price</H5></td>");print("<td><H5>Discount</H5></td>");print("<td width=\"110\"><H5>Net Price</H5></td>");print("<td><H5>Quantity</H5></td>");print("<td width=\"60\"><H5>Total</H5></td>");//print("<td><H5>Grand</H5></td>");$query = "select * from employee where employee.date='$_POST[date]'"; $mysql_result = mysql_query($query, $mysql_link);while($row = mysql_fetch_row($mysql_result)) { print("<h3></h3>"); print("<form action=\"8_storeAdminMenu.php\">"); print("<table width=\"760\" border=\"0\" cellpadding=\"3\">\n");printf("<tr><td width=\"15\">%s</td>",$row[0]);printf("<td width=\"70\">%s</td>", $row[1]);printf("<td width=\"90\">%s</td>", $row[2]);printf("<td width=\"50\">%s</td>",$row[3]);printf("<td width=\"45\">%s</td>",$row[4]);printf("<td width=\"50\" align=right>%s</td>",$row[5]);printf("<td width=\"40\" align=right>%s</td>",$row[6]);printf("<td width=\"43\" align=right>%s</td>", $row[7]);printf("<td width=\"35\" align=right>%s</td>",$row[8]);printf("<td width=\"35\" align=right>%s</td>",$row[9]); print("<input type=\"hidden\" name=\"nav\" value=\"Daily Sales\">"); print("<input type=\"hidden\" name=\"action\" value=\"Edit\">"); printf("<input type=\"hidden\" name=\"no\" value=\"%s\">", $date); print("</table>"); print("</form>"); }$result = mysql_query("SELECT sum(total) FROM employee where employee.date='$date'");echo "Grand Total: ";echo mysql_result($result,0); include("8_dbdisconnect.php"); }?> Link to comment https://forums.phpfreaks.com/topic/27539-how-to-retrieve-mysql-to-a-list-box/#findComment-126028 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.