Click to See Complete Forum and Search --> : search.php + if statmant


LogicOpinion
10-07-2007, 07:24 AM
hello,

i want to search my database and i created search.php file.

here is the code:

<?php

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("mynews") or die(mysql_error());
$query = "SELECT * FROM newsdb WHERE date like '%$keyword%' or title like '%$keyword%' or rte1 like '%$keyword%'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{

print "<table cellpadding=0 cellspacing= width=100% width=700>";
print "<tr><td height=20 class=\"date\" bgcolor=#E0E0E0 style=\"BORDER-BOTTOM:1px #1E90FF solid;\">&nbsp;&nbsp;<B>"; echo $row['date']; print "</B></td></tr>";
print "<tr><td>"; print "<br>"; echo $row['title']; print "</td></td>";
print "<tr><td align=right>";
echo "<a class=\"more\" href='read_news.php?id=".$row['id'] ."'>დაწვრილებით...</a>";
print "<br><br>";
print "</td></td>";
print "</table>";

}

?>

but if the search field is empty and i press "search" button, search.php displays all the data from DB, instead of this i want something like this: if searchword is not specified to echo "please insert search word" but if the searchword is inserted to do the action from above code.

how can do that? i know its if statmant function but could not write it right way.. please help me.

LogicOpinion
10-07-2007, 10:05 AM
is anyvbody gonna reply for my help question?
i do not think if it is so hard to you to explane whats wrong!

please help somebody ...

scragar
10-07-2007, 10:48 AM
if(strlen($keyword) > 0){// increase 0 if you want more than 1 character or 2 in future.
// all your normal retriving info etc goes here.
}else{
echo "your query is too short";
};

LogicOpinion
10-08-2007, 02:56 AM
thank you man!:)