contra10 Posted March 29, 2009 Share Posted March 29, 2009 i'm trying to find a caption phrase using "like" i tried breaking down the work into a string and search the query closest to that word submitted in the form. Also if the city is selected then it would have to be that specific caption phrase in the city selected <?php //This code runs if the form has been submitted if(isset($_POST['submit']) and ($_POST['caption'])) { $city = "{$_POST['city']}"; $caption = "{$_POST['caption']}"; $search_text=$_POST['caption']; $search_text=ltrim($search_text); $search_text=rtrim($search_text); $kt=split(" ",$search_text); while(list($key,$val)=each($kt)){ if($val<>" " and strlen($val) > 0){$q .= " `caption` like '%$val% or ";} } $q=substr($q,0,(strLen($q)-3)); $query="SELECT * FROM `images` WHERE $q"; if(isset($_POST['submit']) and ($_POST['caption']) and ($_POST['city'])){$query .= "and `city` = '$city' ";} $img = mysql_query($query); while($getimg = mysql_fetch_array($img)) { $imageid= "{$getimg['id']}"; $imagecity= "{$getimg['city']}"; $imagecaption= "{$getimg['caption']}"; echo "<img src='http://localhost/pictures/imagereplace.php?id=$imageid'><br>"; echo "$imagecaption"; } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.