search engine script not showing result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
balamberas
Forum Newbie
Posts: 10
Joined: Fri Mar 06, 2009 12:36 pm

search engine script not showing result

Post by balamberas »

Hi, this script wont show the result from my data base, might be here

if ($x==1)
$construct .= " description LIKE '%$search_each%'";
else
$construct .= " AND description LIKE '%$search_each%'";

i tried to change the description to another column like location but no luck.

<?php

include ('connect.php');

$button = $_GET['submit'];
$search = $_GET['search'];

if (!button)

echo "you didnt submit a keyword.";

else

{

if (strlen($search)<=2)

echo "search term to short.";
else
{
echo " You searched for <b>$search</b><hr size='1'>";

//connect to our database

$search_exploded = explode(" ",$search);

foreach($search_exploded as $search_each)

{

// construct query

$x++;
if ($x==1)
$construct .= " description LIKE '%$search_each%'";
else
$construct .= " AND description LIKE '%$search_each%'";

}
// echo out construct

$construct = "SELECT * FROM flats WHERE $construct";
$run = mysql_query($construct);

$foundnum = mysql_num_rows($run);

if (foundnum==0)
echo "No results found.";
else

{
echo "$foundnum result found!<p>";

while ($runrows = mysql_fetch_assoc($run))

{

// get data

$select = $runrows['type'];
$title = $runrows['title'];
$location = $runrows['location'];


echo "

echo $title;
echo <br>;
echo $select;
echo <br>;
echo $rent;
echo <br>;
echo $location;
echo <hr>";

}


}
}
}


?>
hostingon
Forum Newbie
Posts: 6
Joined: Fri Dec 04, 2009 5:00 pm
Location: USA

Re: search engine script not showing result

Post by hostingon »

Hi balamberas !

You can debug this by executing your query directly in mysql when it is done after this:

$construct = "SELECT * FROM flats WHERE $construct";
give to your self one echo of this $construct to see it.
If your mysql return zero rows - evertything is ok with mysql, but there is not such result in your data base.
balamberas
Forum Newbie
Posts: 10
Joined: Fri Mar 06, 2009 12:36 pm

Re: search engine script not showing result

Post by balamberas »

Hi,

sorry but i dont know the right syntax to use in able to see what the errors are. I did SELECT * FROM table_name and got the results from my database table.
Post Reply