danbb
04-25-2010, 09:23 AM
Hello.
Im trying to build a php form (drop down) that will change my mysql query, some kind of a filter.
this is my php code :
<?php
$username="***";
$password="****";
$database="****";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
if (isset($_GET['subject']))
{
switch($_GET['subject'])
{
case 'field1':
$query = "select * from employees where email LIKE '%$field1%'";
break;
case 'field2':
$query = "select * from employees where email LIKE 'field2' ";
break;
default:
echo 'No subject found';
$query = false;
}
}
if ($query){
$result=mysql_query($query);
$numrows=mysql_num_rows($result);
}
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"last_name");
$f2=mysql_result($result,$i,"tests");
$f3=mysql_result($result,$i,"email");
$f5=mysql_result($result,$i,"hire_date");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
<td style="width: 80px;"><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td>
</tr>
<?php
$i++;
}
?>
and this is the form :
<form name="form" action="<? print $_SERVER['PHP_SELF']?>" method="get">
<select name="subject">
<option value=""></option>
<option value="תל אביב">תל אביב</option>
<option value="field2">תל אביב</option>
</select>
<input type="submit" name="Submit" />
</form>
thank you very much for your help!
Im trying to build a php form (drop down) that will change my mysql query, some kind of a filter.
this is my php code :
<?php
$username="***";
$password="****";
$database="****";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
if (isset($_GET['subject']))
{
switch($_GET['subject'])
{
case 'field1':
$query = "select * from employees where email LIKE '%$field1%'";
break;
case 'field2':
$query = "select * from employees where email LIKE 'field2' ";
break;
default:
echo 'No subject found';
$query = false;
}
}
if ($query){
$result=mysql_query($query);
$numrows=mysql_num_rows($result);
}
$i=0;
while ($i < $num) {
$f1=mysql_result($result,$i,"last_name");
$f2=mysql_result($result,$i,"tests");
$f3=mysql_result($result,$i,"email");
$f5=mysql_result($result,$i,"hire_date");
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
<td style="width: 80px;"><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td>
</tr>
<?php
$i++;
}
?>
and this is the form :
<form name="form" action="<? print $_SERVER['PHP_SELF']?>" method="get">
<select name="subject">
<option value=""></option>
<option value="תל אביב">תל אביב</option>
<option value="field2">תל אביב</option>
</select>
<input type="submit" name="Submit" />
</form>
thank you very much for your help!