View Single Post
Old 02-20-2013, 10:35 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,162
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I don't use PHP.

I'll give it a try, but don't be surprised if I mess up the PHP code.
Code:
<?php

$search = $_POST["search"];
$words = explode( " ", $search ); // get array of words
$pattern = "";
for ( $w = 0; $w < count($words); ++$w )
{
    $word = $wods[$w];
    if ( $word != "" )
    {
        if ( $pattern != "" ) $pattern .= " AND "; // or use " OR " as discussed!
        $pattern .= " ## LIKE '%" . $word . "%' ";
    }
]
if ( $pattern == "" )
{
    echo "You didn't give me anything to search for!  I quit!";
    exit( );
}

$pattern = "( " . $pattern . ") ";
$where = " WHERE " . str_replace( "##", "name", $pattern );
$where .= " OR " . str_replace( "##", "city", $pattern );
$where .= " OR " . str_replace( "##", "notes", $pattern );
$where .= " OR " . str_replace( "##", "moreinfo", $pattern );
$where .= " OR " . str_replace( "##", "amenities", $pattern );

$sql = "SELECT * FROM campground " . $where . " ORDER BY name";

// remove next line after it starts working
echo "DEBUG SQL: " . $sql . "<hr/>\n";

$result = mysql_query( $sql ) or die( mysql_error() );

,,, etc ,,,
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
SlayerACC (02-21-2013)