Jump to content

Query based on option in dropdown list


Yann63

Recommended Posts

I want to see the content of a query on a webpage based on an option selected in a dropdown list (sort of filter function)

I made following javascript and PHP script but doesn't receive the desired result (no records).

What do I do wrong ?

< script type="text/javascript">
function MM_callJS(jsStr) { //v2.0
var opd = document.form1.opdstatus.options[document.form1.opdstatus.selectedIndex].text;
alert (opd);
< ?php
mysql_select_db($database_myconnection, $myconnection);
if (opd == "Started") {
$query_dashboard = "SELECT * FROM dashboard WHERE Status = 'ST' ORDER BY Deadline ASC";
$dashboard = mysql_query($query_dashboard, $myconnection) or die(mysql_error());
$row_dashboard = mysql_fetch_assoc($dashboard);
$totalRows_dashboard = mysql_num_rows($dashboard);
}
if (opd == "Finished") {
$query_dashboard = "SELECT * FROM dashboard WHERE Status = 'FN' ORDER BY Deadline ASC";
$dashboard = mysql_query($query_dashboard, $myconnection) or die(mysql_error());
$row_dashboard = mysql_fetch_assoc($dashboard);
$totalRows_dashboard = mysql_num_rows($dashboard);
}
if (opd == "Pending") {
$query_dashboard = "SELECT * FROM dashboard WHERE Status = 'PN' ORDER BY Deadline ASC";
$dashboard = mysql_query($query_dashboard, $myconnection) or die(mysql_error());
$row_dashboard = mysql_fetch_assoc($dashboard);
$totalRows_dashboard = mysql_num_rows($dashboard);
}
if (opd == "All") {
$query_dashboard = "SELECT * FROM dashboard ORDER BY Deadline ASC";
$dashboard = mysql_query($query_dashboard, $myconnection) or die(mysql_error());
$row_dashboard = mysql_fetch_assoc($dashboard);
$totalRows_dashboard = mysql_num_rows($dashboard);
}
?>
}
< /script>

 

Link to comment
https://forums.phpfreaks.com/topic/277935-query-based-on-option-in-dropdown-list/
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.