ragrim Posted March 29, 2010 Share Posted March 29, 2010 Hi, I have a page displaying a list of records, i want to display these record based on a combo box which just says to display records with status, open, closed or all. im not sure how to do this and im pretty sure im wrong, but heres what i came up with <?php $sql = ""; if(isset($_POST['submit'])) { $queryvar = $_POST["combo1"]; if ($queryvar == "All") //Echo "You are viewing all records"; $sql = mysql_query("SELECT * FROM tblworkorders WHERE status = ''"); elseif ($queryvar == "Open") //echo "you are viewing all Open records"; $sql = mysql_query("SELECT * FROM tblworkorders WHERE status = 'Open'"); elseif ($queryvar == "Closed") //echo "Viewing all Closed records"; $sql = mysql_query("SELECT * FROM tblworkorders WHERE status = 'Closed'"); } echo "query" . $sql; $con = mysql_connect("localhost","root",""); mysql_select_db(it, $con); $result = $sql; $num=mysql_numrows($result); mysql_close(); ?> The error i am getting is Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\it\ifelsetest.php on line 30 im guessing the $sql variable is not global or something, im not too sure. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/196832-mysql-query-based-on-combo-box-selection/ Share on other sites More sharing options...
fenway Posted March 29, 2010 Share Posted March 29, 2010 Find which query is causing the problem, and check mysql_error(). Link to comment https://forums.phpfreaks.com/topic/196832-mysql-query-based-on-combo-box-selection/#findComment-1033427 Share on other sites More sharing options...
andrewgauger Posted March 29, 2010 Share Posted March 29, 2010 If your echo line is outputting: query Your conditional isn't working as expected. Debug higher: put an echo $_POST["combo1"]; Also please, use more meaningful names than combo1. Link to comment https://forums.phpfreaks.com/topic/196832-mysql-query-based-on-combo-box-selection/#findComment-1033598 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.