Im trying to use this code to search my marker database and the only
thing not working is the "loc" row sometimes has spaces in the
database. Is there a way to get rid of the spaces? Example - an entry
might be 23 K 2323, when people search i want them to be able to just
put in 23K and get the results. Heres the search code.
<?php
/
**************************************************************************************
* Main Search Page - search.php
* Author: Your Name <[EMAIL PROTECTED]>
* This file searches the database
**************************************************************************************/
//Get variables from config.php to connect to mysql server
require 'config.php';
// connect to the mysql database server.
mysql_connect ($dbhost, $dbusername, $dbuserpass);
//select the database
mysql_select_db($dbname) or die('Cannot select database');
//search variable = data in search box or url
if(isset($_GET['search']))
{
$search = $_GET['search'];
}
//trim whitespace from variable
$search = trim($search);
$search = preg_replace('/\s+/', ' ', $search);
//seperate multiple keywords into array space delimited
$keywords = explode(" ", $search);
//Clean empty arrays so they don't get every row as result
$keywords = array_diff($keywords, array(""));
//Set the MySQL query
if ($search == NULL or $search == '%'){
} else {
for ($i=0; $i<count($keywords); $i++) {
$query = "SELECT * FROM geopoints " .
"WHERE prnum LIKE '%".$keywords[$i]."%'".
" or address LIKE '%".$keywords[$i]."%'".
" OR prname LIKE '%".$keywords[$i]."%'" .
" OR cli LIKE '%".$keywords[$i]."%'" .
" OR loc LIKE '%".$keywords[$i]."%'" .
" OR zip LIKE '%".$keywords[$i]."%'" .
" ORDER BY prnum";
}
//Store the results in a variable or die if query fails
$result = mysql_query($query) or die(mysql_error());
}
if ($search == NULL or $search == '%'){
} else {
//Count the rows retrived
$count = mysql_num_rows($result);
}
echo "<html>";
echo "<head>";
echo "<title>Your Title Here</title>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" /
>";
echo "</head>";
echo "<body onLoad=\"self.focus();document.searchform.search.focus()
\">";
echo "<center>";
echo "<br /><form name=\"searchform\" method=\"GET\" action=
\"search.php\">";
echo "<input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" /
>";
echo " <input type=\"submit\" value=\"Search\" />";
echo "</form>";
//If search variable is null do nothing, else print it.
if ($search == NULL) {
} else {
echo "You searched for <b><FONT COLOR=\"blue\">";
foreach($keywords as $value) {
print "$value ";
}
echo "</font></b>";
}
echo "<p> </p><br />";
echo "</center>";
//If users doesn't enter anything into search box tell them to.
if ($search == NULL){
echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter
to continue.</font></b><br /></center>";
} elseif ($search == '%'){
echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter
to continue.</font></b><br /></center>";
//If no results are returned print it
} elseif ($count <= 0){
echo "<center><b><FONT COLOR=\"red\">Your query returned no results
from the database.</font></b><br /></center>";
//ELSE print the data in a table
} else {
//Colors for alternation of row color on results table
$color1 = "#d5d5d5";
$color2 = "#e5e5e5";
//While there are rows, print it.
while($row = mysql_fetch_array($result))
{
//Row color alternates for each row
$row_color = ($row_count % 2) ? $color1 : $color2;
//table background color = row_color variable
echo "<center><table bgcolor=".$row_color.">";
echo "<tr>";
echo "<fontsize=12>";
echo "<td><a target=\"_parent\" href=\"http://www.windengr.com:2322/
pfn/phpsqlajax_map.htm?id=".$row['prnum']."\">".$row['prnum']."</td>";
echo "<td>".$row['zip']."</td>";
echo "<td>".$row['loc']."</td>";
echo "</fontsize>";
echo "</tr>";
echo "</table></center>";
$row_count++;
//end while
}
//end if
}
echo "</body>";
echo "</html>";
if ($search == NULL or $search == '%') {
} else {
//clear memory
mysql_free_result($result);
}
?>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---