Jump to content

Mysql query based on combo box selection


ragrim

Recommended Posts

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

 

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.