Jump to content
Sign in to follow this  
**nor

Coding Search Untuk Search Maklumat Dalm Website Sahaja

Recommended Posts

assalamualaikum..
nak tanya sikit nak kena tambah apa dalm coding ne ye.. nak buat search untuk search maklumat dlam website jew.. x nak search luar.. dan nak tau jugak kena guna database kew??

[CODE]<?php
error_reporting (E_ALL ^ E_NOTICE);
$button = $_GET ['submit'];
$search = $_GET ['search'];
if(!$button)
echo "you didn't submit a keyword";
else
{
if(strlen($search)<=1)
echo "Search term too short";
else{
echo "You searched for <b>$search</b> <hr size='1'></br>";
mysql_connect("localhost","root","");
mysql_select_db("dbspa");
$search_exploded = explode (" ", $search);
foreach($search_exploded as $search_each)
{
$x++;
if($x==1)
$construct .="keywords LIKE '%$search_each%'";
else
$construct .="AND keywords LIKE '%$search_each%'";
}
$construct ="SELECT * FROM searchengine WHERE $construct";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);
if ($foundnum==0)
echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1.
Try more general words. for example: If you want to search 'how to create a website'
then use general keyword like 'create' 'website'</br>2. Try different words with similar
meaning</br>3. Please check your spelling";
else
{
echo "$foundnum results found !<p>";
while($runrows = mysql_fetch_assoc($run))
{
$title = $runrows ['title'];
$desc = $runrows ['description'];
$url = $runrows ['url'];
echo "
<a href='$url'><b>$title</b></a><br>
$desc<br>
<a href='$url'>$url</a><p>
";
}
}
}
}
?>[/CODE]

Share this post


Link to post
Share on other sites
[quote][color=#282828][font=helvetica, arial, sans-serif][size=3] dan nak tau jugak kena guna database kew??[/size][/font][/color][/quote]

Dari hasil coding ini terang2 cari dalam database.. hehehe...

[CODE]
echo "You searched for <b>$search</b> <hr size='1'></br>";
mysql_connect("localhost","root","");
mysql_select_db("dbspa");
[/CODE]

Share this post


Link to post
Share on other sites
coding ni memamg da coding untuk search. cuma perlu di tambah baik semula. gunakan [b]htmlentities[/b] untuk mengelakkan jangkitan XSS. hohoho

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...