simple search algorithm

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

simple search algorithm

Post by kkonline »

Hi I am in process of making a search script. When i write the below code it doesn't give any result. also it doesn't enter the while loop. When i write the query in sql, no results are displayed.

What could be the reason?

Code: Select all

 
if (content_type($section_id,$fetched_section)==0)//type=text
{
$sqlcontent = "SELECT * FROM $fetched_section WHERE `trusted` = 1 AND title LIKE '".$query."%' And content LIKE '".$query."%' ORDER BY `title` ASC LIMIT 0, 10";
 
$resultcontent = mysql_query($sqlcontent) or die(mysql_error());
 
while($row = mysql_fetch_array($resultcontent)){
echo 'we are  here'; 
echo $row['id'];
 
echo $row['content'];
}
}
else
echo 'non text';
 
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: simple search algorithm

Post by pickle »

kkonline wrote:When i write the query in sql, no results are displayed.
Sounds like your query isn't returning any results. That's not a bug, that's an improperly built query.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: simple search algorithm

Post by Mordred »

title like query OR content like query
Post Reply