
Originally Posted by
driveflexfuel
...
2 Search by state i have an image map where they can click on the state and it needs to display all resutls for that state on another page. Image map adds the variable page.php?state=california if you click california
...
If I understood correctly, you already have an image map where users can click on the state.
PHP Code:
<?php
/*
File name: by_state.php
Expecting something like : by_state.php?state=california
Note that 'california' is not the same as 'ca'
but california will match CaliFORnia.
Your MySql table must contain a field named STATE.
*/
if (isset($_GET['state']) ) {
// Connect
$db_server = "localhost";
$database = "*******";
$db_user = "********";
$db_pass = "********";
// Reverse magic_quotes_gpc/magic_quotes_sybase effects on those vars if ON.
if(get_magic_quotes_gpc()) {
$sstate = stripslashes($_GET['state']);
} else {
$sstate = $_GET['state'];
}
mysql_connect($db_server,$db_user,$db_pass);
@mysql_select_db($database) or die( "Unable to select database");
$query = sprintf("SELECT * from company WHERE `STATE` LIKE \"$sstate\" ORDER BY BUSINESS ASC");
$result = mysql_query($query);
$num = mysql_num_rows($result);
mysql_close();
if ($num < 1) {
echo "No Business found in the State of " . $_GET['state'] . "\n";
} else {
// Build the table with results
?>
<table>
<tr>
<td>BUSINESS</td>
<td>OWNERNAME</td>
<td>PHONE</td>
<td>ADDRESS</td>
<td>CITY</td>
<td>STATE</td>
<td>ZIPCODE</td>
</tr>
<?php $i=0;
while ($i < $num) { ?>
<tr>
<td><?php echo mysql_result($result, $i, 'BUSINESS'); ?></td>
<td><?php echo mysql_result($result, $i, 'OWNERNAME'); ?></td>
<td><?php echo mysql_result($result, $i, 'PHONE'); ?></td>
<td><?php echo mysql_result($result, $i, 'ADDRESS'); ?></td>
<td><?php echo mysql_result($result, $i, 'CITY'); ?></td>
<td><?php echo mysql_result($result, $i, 'STATE'); ?></td>
<td><?php echo mysql_result($result, $i, 'ZIPCODE'); ?></td>
</tr>
<?php
++$i;
} ?>
</table>
<?php
}
}
?>