...

View Full Version : all db entries on main search page



may_bailey
08-27-2009, 08:43 PM
Hi,

I created a page for my dictionary search. But the problem is when I open the page I see all the words / vocabulary as a list under my search box. How can I fix this?


and also, how can I add a script to show a message like "please write a word in order to search" if someone seeks sth without writing sth in the box.

regards

my codes are:


$search=$_POST["search"];

$result = $result = mysql_query("SELECT * FROM dictionary WHERE tr LIKE '%$search%' OR it LIKE '%$search%'");
while($r=mysql_fetch_array($result))
{
$tr=$r["tr"];
$it=$r["it"];
$id=$r["id"];

//the result goes here.

if ($search==$it){
echo "$it = $tr";
} else {
echo "$tr = $it";
}
echo "<a href=".$url.">".$url."</a><br>";
}

if ($id==0){
echo "No record for that search.";
}
if ($search==""){
echo "Please write down a word to look for.";
}

?>

Phil Jackson
08-27-2009, 08:57 PM
if(isset($_POST["submitButtonName"])) //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EDIT
{
$search = $_POST["search"];
if(!empty($search))
{
$result = $result = mysql_query("SELECT * FROM dictionary WHERE tr LIKE '%$search%' OR it LIKE '%$search%'");
if(mysql_num_rows($result)!=0)
{
while($r=mysql_fetch_array($result))
{
$tr=$r["tr"];
$it=$r["it"];
$id=$r["id"];
//the result goes here.
if ($search==$it)
{
echo "$it = $tr";
}
else
{
echo "$tr = $it";
}
echo "<a href=".$url.">".$url."</a><br>";
}
}
else
{
echo "No record for that search.";
}
}
else
{
echo "Please write down a word to look for.";
}
}

may_bailey
08-28-2009, 09:41 AM
Thanks a lot for your reply Phil,
But I get an error like:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/bailey/public_html/search_result.php on line 43
No record for that search.

and I think the line 43 is here:



$result = $result = mysql_query("SELECT * FROM dictionary WHERE tr LIKE '%$search%' OR it LIKE '%$search%'");
if(mysql_num_rows($result)!=0) -> I Think it's here <-
{
while($r=mysql_fetch_array($result))
{


How can I solve that?

Fou-Lu
08-28-2009, 09:48 AM
You're assumption of the problem is correct for its location. Although odd, $a = $a = $b, is a valid syntax so you're just overwriting the result of $result with $result. Funny as that sounds.
There is no error checking here, the problem is with you're query and / or connectivity.


$result = mysql_query("SELECT * FROM dictionary WHERE tr LIKE '%$search%' OR it LIKE '%$search%'") or die(mysql_error());

Run that, it will tell you what is wrong with you're query or connection.

may_bailey
08-28-2009, 10:04 AM
Thanks a lot Fou-Lu.
When I try the thing you said I saw the reason. Wrong database name =D
my inexperience :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum