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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.