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
https://forums.phpfreaks.com/topic/142649-solved-search-db-help/
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>"; 
}

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.