/    Sign up×
Community /Pin to ProfileBookmark

search.php + if statmant

[B]hello,

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

here is the code:[/B]

[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’] .”‘>&#4307;&#4304;&#4332;&#4309;&#4320;&#4312;&#4314;&#4308;&#4305;&#4312;&#4311;…</a>”;
print “<br><br>”;
print “</td></td>”;
print “</table>”;

}

?>[/CODE]

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.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@LogicOpinionauthorOct 07.2007 — 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 ...
Copy linkTweet thisAlerts:
@scragarOct 07.2007 — [code=php]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";
};
[/code]
Copy linkTweet thisAlerts:
@LogicOpinionauthorOct 08.2007 — thank you man!?
×

Success!

Help @LogicOpinion spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...