Jump to content

Need help in modifying script to search database. Thank you!


bchandel

Recommended Posts

Hello,

 

I need help in modifying the script below. Thank you for your time and help!

 

I have this script which works fine in displaying the records from database. I have a form where a visitor can enter values for City, State and Country. How can I modify this script so it only display data where City is like "% $ %" or State is like "% $%" or Country is like "% $ %"

 

$ = Out put (City, state, Country) entered by the visitor using form.

 

Basically, I am looking to display data meeting Is like criteria from the form. I hope I am able to clarify.

 

 

<?php

$db_connect = mysql_connect("xxx.com", "xxx_user", "password");

mysql_select_db("xxx_database", $db_connect) or die( "Unable to select database");

$query = "SELECT * FROM Business";

$result = mysql_query($query);

$num=mysql_num_rows($result);

?>

<html>

<head>

<style type="text/css">

.custom {font-family: Arial, Helvetica, sans-serif; }

body

{

background-color:#ffffbo;

border-top:blue solid 50px;

border-left:blue solid 50px;

}

 

</style>

</head>

 

</style>

<head>

 

<body>

 

<h1><font color="#000080">Search Results:</font></h1>

 

 

<table border="5" width="100%" cellspacing="1" cellpadding="5" bordercolor="#000080">

<tr>

<th class="custom">Business</th>

<th class="custom">Type</th>

<th class="custom">Contact</th>

<th class="custom">E-mail</th>

<th class="custom">Web Site</th>

<th class="custom">Phone</th>

<th class="custom">Fax</th>

<th class="custom">Address</th>

<th class="custom">Address2</th>

<th class="custom">City</th>

<th class="custom">State</th>

<th class="custom">Zip</th>

<th class="custom">Country</th>

<th class="custom">Profile</th>

</tr>

<?php

while($d = mysql_fetch_array($result)) {

 

$d['Email'] = $d['Email'] ? "<a href='mailto:{$d['Email']}'>E-mail</a>" : "-";

$d['WebSite'] = $d['WebSite'] ? "<a href='{$d['WebSite']}'>Web Site</a>" : "-";

$d['Profile']= $d['Profile'] ? "<a href='{$d['Profile']}'>Profile</a>" : "-";

 

echo "<tr>

<td class='custom'>{$d['Business']}</td>

<td class='custom'>{$d['Type']}</td>

<td class='custom'>{$d['Contact']}</td>

<td class='custom'>{$d['Email']}</td>

<td class='custom'>{$d['WebSite']}</td>

<td class='custom'>{$d['Phone']}</td>

<td class='custom'>{$d['Fax']}</td>

<td class='custom'>{$d['Address']}</td>

<td class='custom'>{$d['Address2']}</td>

<td class='custom'>{$d['City']}</td>

<td class='custom'>{$d['State']}</td>

<td class='custom'>{$d['Zip']}</td>

<td class='custom'>{$d['Country']}</td>

<td class='custom'>{$d['Profile']}</td>

</tr>";

 

}

?>

</table>

 

  </body>

  </html>

Thank you for your help. Should I enter this as below. Please check positions for " and ;

 

$query = "SELECT * FROM Business; WHERE City LIKE '%$variable%'"

 

How to add other variables say state and Country. City LIKE '%$variable' or State LIKE '%$variable' or Country LIKE '%$variable%';

 

Thank you!

 

 

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.