Jump to content

[SOLVED] find an image with like


contra10

Recommended Posts

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";
	}
	}

	?>

Link to comment
https://forums.phpfreaks.com/topic/151566-solved-find-an-image-with-like/
Share on other sites

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.