Jump to content

[SOLVED] Search DB Help


phpretard

Recommended Posts

This only displays one result and I can't figure out why...

 

There are 2 fields in the DB I am trying to search through and look for the keyword typed in the search field:

FIELD 1:casetype VARCHAR

FIELD 2:caseinfo TEXT

 

I can get it search and display all when search one field at a time but it only dispalys one result if I try to search both fields.

 

$find=$_POST['find'];

$data = mysql_query("SELECT * FROM cases WHERE (casetype or caseinfo LIKE'%$find%') ");
	while($result = mysql_fetch_array($data)) 
	{ 
	$id=$result['id'];
	echo "<h1>".$result['casetype']."</h1>"; 
	echo "<hr />";
	$caseinfo=$result['caseinfo'];
	$caseinfofull=$result['caseinfo'];
	echo"<div id='$id' style='display:none'>$caseinfofull [<a href='javascript:void(0)' onclick=\"Hide('$id'), Show('partial$id')\">close</a>]</div>";
	echo "<div id='partial$id' style='display:block'>".$shortdesc = substr_replace($caseinfo, '', 400, -1) . "... <a href='javascript:void(0)' onclick=\"Show('$id'), Hide('partial$id')\">read more</a></div>"; 
	echo "<br>"; 
	echo "<br>"; 
	} 

Link to comment
Share on other sites

Basically the same as my first question but I noticed if I search with more than one word it returns nothing.

 

$find="ONE"; // WORKS GREAT
$find="TWO WORDS"; // NO RESULTS ... I KNOW THERE IN THE DB THOUGH

$find = strtoupper($find); 
$find = strip_tags($find); 
$find = trim ($find); 

$data = mysql_query("SELECT * FROM cases WHERE (casetype LIKE '%$find%') OR (caseinfo LIKE '%$find%') ");
while($result = mysql_fetch_array($data)) 
{ 
echo "<h1>".$result['casetype']."</h1>"; 
echo "<hr />";
$caseinfo=$result['caseinfo'];
$caseinfofull=$result['caseinfo'];
echo $caseinfofull;
echo $shortdesc = substr_replace($caseinfo, '', 400, -1) . "; 
echo "<br>"; 
echo "<br>"; 
}

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.