جستجو در اطلاعات پايه
Upload<html>
<head>
<title>kayvan shojaei: Database Search</title>
</head>
<body>
<p align="center">Database Search</p>
<?php
//*************************************
//** SEARCH SCRIPT BY: kayvan shojaei **
//*************************************
//*************************************
//** CODE**
//*************************************
$connection = mysql_connect("server.server.server","user","passw ord");
if(!$connection){
echo "Couldn't make a connection!!!";
exit;
}
$db = mysql_select_db("database_name",$connection);
if(!$db) {
echo "The database disapeared!";
mysql_close($connection);
exit;
}
$max = 0;
$bmax = mysql_query("SELECT * from table WHERE columntobesearched like '%$search%'");
while ($result = mysql_fetch_array($bmax)) {
$max++;
}
?>
<table border="0" cellspacing="0" width="100%">
<tr>
<td height="12" align="left" background="bg2.jpg" width="50%">
<?php
echo "<form action=\"search.php\" method=\"get\"><input type=\"text\" name=\"search\" value=\"$search\"><input type=\"submit\" value=\"Search\">";
echo "</td><td height=\"12\" align=\"right\" bgcolor=\"red\" width=\"50%\">";
echo "By: Todd Williams";
echo "<td height=\"12\" align=\"right\" background=\"bg2.jpg\" width=\"100%\" colspan=\"2\">";
echo "<center>Database Search returned $max items containing \"<i>$search</i>\".</center>";
echo "</td></tr></table></form>";
$maxresult = 10;
$sql_text = ("SELECT * from table WHERE columntobesearched like '%$search%'");
if (!$page) {
$page = 1;
}
$backpage = $page - 1;
$nextpage = $page + 1;
$query = mysql_query($sql_text);
$start = ($maxresult * $page) - $maxresult;
$num_rows = mysql_num_rows($query);
if ($num_rows <= $maxresult) {
$num_pages = 1;
} else if (($num_rows % $max result) == 0) { $num_pages = ($num_rows / $maxresult);
} else {
$num_pages = ($num_rows / $maxresult) + 1;
}
$num_pages = (int) $num_pages;
if (($page > $num_pages) || ($page < 0)) {
error("You have specified an invalid page number");
}
$sql_text = $sql_text . " LIMIT $start, $maxresult";
$query = mysql_query($sql_text);
if ($max>$maxresult)
{
echo "<center>- ";
if ($backpage) {
echo "<a href=\"search.php?search=$search&page=$backpage\"> Prev</a>";
} else {
echo "Prev";
}
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $page) {
echo " <a href=\"search.php?search=$search&page=$i\">$i</a> ";
} else {
echo " $i ";
}
}
if ($page != $num_pages) {
echo "<a href=\"search.php?search=$search&page=$nextpage\"> Next</a> -";
} else {
echo "Next -";
}
echo "</center>";
}
?>
<table border="0" cellspacing="0" width="100%">
<?php
$a = $start + 1;
while ($result = mysql_fetch_array($query)) {
?>
<tr>
<td height="12" align="left" background="bg2.jpg" width="70%">
<?php
printf("$a. <a href=\"%s\">", $result['linkcolumn']);
printf("%s </a></td><td align=\"right\" background=\"bg2.jpg\">", $result['namecolumn']);
printf("%s ", $result['authorcolumn']);
printf("</a>");
$a++;
?>
</td>
</tr>
<tr>
<td colspan="2">
<?php printf("%s <br>", $result['descriptioncolumn']); ?>
</td>
</tr>
<?php
}

echo "</table>";
if ($max>$maxresult)
{
echo "<br><br><br><center>- ";
if ($backpage) {
echo "<a href=\"search.php?search=$search&page=$backpage\"> Prev</a>";
} else {
echo "Prev";
}
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $page) {
echo " <a href=\"search.php?search=$search&page=$i\">$i</a> ";
} else {
echo " $i ";
}
}
if ($page != $num_pages) {
echo "<a href=\"search.php?search=$search&page=$nextpage\"> Next</a> -";
} else {
echo "Next -";
}
echo "</center>";
}
?>
</body>
</html>