Since i don't use my i guess someone else can get something out of it.
Mysql:
Run that in phpmyadminCode:CREATE TABLE search( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30) NOT NULL, url VARCHAR(30) NOT NULL, about TEXT NOT NULL)';
Index.php
Basicly Just the search formHTML Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> <link type="text/css" rel="stylesheet" href="/css.css"> </head> <body> <div align="center"> <img style="margin: 0px;" width="690" height="150" src="banner url here" alt="" title=""> <br></div> <center> <form action="search.php" method="get"><font size="1" face="Verdana"><strong>Search:</strong></font> <input type="text" size="20" name="search"> <input type="submit" value="Search!"></form> <table style="border: 1px solid rgb(0, 0, 0);" width="50%"></table><font size="1" face="Verdana"><span class="nav">| <a title="" href="/add.php">Add Your Site</a> | </span></font> <br></center> </body> </html>
ADD.PHP
make sure to put your details to mysql in.PHP Code:<center><?php // set your infomation.
$dbhost='localhost'; // host
$dbusername='colin_shout'; // database username
$dbuserpass='cococo'; // database password
$dbname = 'colin_search'; //database
// connect to the mysql database server.
mysql_connect ($dbhost, $dbusername, $dbuserpass);
//select the database
mysql_select_db($dbname) or die('Cannot select database');
//submits the form
if ($_POST['name']) {
$name = $_POST['name'];
if ($_POST['about']) {
$about = $_POST['about'];
if ($_POST['url']) {
$url = $_POST['url'];
// inserts the results into mysql $query = "INSERT INTO search (name,about,url) VALUES ('".$name."','".$about."','".$url."')"; mysql_query($query)or die(mysql_error());
echo $name." was inserted successfully";
}else{
echo "About/Url was left blank";
//echos if they missed a feild
}
}
}
?>
<html>
<head>
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<title></title>
<link type="text/css" rel="stylesheet" href="/css.css">
</head>
<body>
<img style="margin: 0px;" width="690" height="150" src="banner url" alt="" title="">
<br></div>
<form action='add.php' method='POST'>
<font size="1" face="Verdana">Name:</font><input type='text' name='name' size='33' /></br>
<font size="1" face="Verdana">Url:</font><input type='text' name='url' size='33' /></br>
<font size="1" face="Verdana">About:</font><textarea name='about' cols='25' rows='5'/></textarea></br>
<input type='submit' value='Add!' />
</form>
<span class="nav"><font size="1" face="Verdana"><span class="nav">| <a href="/add.php" title="">Add Your Site</a> | <a href="/index.php">Search</a> | </span></font>
</center>
</body>
</html>
Search.php
agian make sure to add your detailsPHP Code:<?php $dbhost='localhost'; //host $dbusername='colin_shout'; //database username $dbuserpass='cococo'; //database pass$dbname = 'colin_search'; //database search mysql_connect ($dbhost, $dbusername, $dbuserpass); mysql_select_db($dbname) or die('Cannot select database'); // connects to database
$rowsPerPage = 5; //amount of search results per page
$pageNum = 1;
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
if(isset($_GET['search']))
{
$search = $_GET['search'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage; //offsets page number
$keywords = explode(" ", $search); //graps searched word
$query = "SELECT id,name,about,url FROM search " .
"WHERE about LIKE '%".$keywords['0']."%'"; // searches for searched word in database
for ($i=1; $i<count($keywords); $i++) {
$query = $query." AND about LIKE '%".$keywords[$i]."%'"; //counts the results
}
$query = $query." ORDER BY id LIMIT $offset, $rowsPerPage"; //orders by rank
$result2 = mysql_query($query) or die(mysql_error()); // kills mysql if query didnt work
?>
<html>
<head>
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<title></title>
<link type="text/css" rel="stylesheet" href="/css.css">
</head>
<body>
<center>
<img style="margin: 0px;" width="690" height="150" title="" alt="" src="banner url">
</br>
<form method="GET" action="search.php">
<b>Search:</b> <input type="text" name="search" size="20" />
<input type="submit" value="Search!" />
</form>
<table width="50%" style="border:1px solid #000000;">
</body>
</html>
<?php
$keywords = explode(" ", $search);
$query = "SELECT COUNT(id) AS numrows FROM search " . //displays id number
"WHERE about LIKE '%".$keywords['0']."%'";
for ($i=1; $i<count($keywords); $i++) {
$query = $query." AND about LIKE '%".$keywords[$i]."%'";
}
$result = mysql_query($query) or die('Error, query failed'); //displays error that query failed
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage); //sets number of pages
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++) // shows list of pages
{
if ($page == $pageNum)
{
$nav .= " $page ";
}
else
{
$nav .= " <a href="$self?page=$page&search=$search">$page</a> "; // sets target for pages
}
}
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href="$self?page=$page&search=$search">[Prev]</a> "; // displays option of prev page
$first = " <a href="$self?page=1&search=$search">[First Page]</a> "; //displays option of first page
}
else
{
$prev = ' ';
$first = ' ';
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href="$self?page=$page&search=$search">[Next]</a> "; //displays option of next page
$last = " <a href="$self?page=$maxPage&search=$search">[Last Page]</a> "; //displays option of last page
}
else
{
$next = ' ';
$last = ' ';
}
while($row = mysql_fetch_array($result2))
{
echo "<tr>";
echo "<td style='border-bottom: 1px solid #000000;'>"; //echos tables
echo "<b><a href="".$row['url']."">".$row['name']."</a></b>"; // echos the results name
echo "<p>".$row['about']."</p>"; // echos about the result
echo "<p><a href="".$row['url']."">".$row['url']."</a></p>"; //echos about the url
echo "</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td>";
echo "<center>".$first . $prev . $nav . $next . $last."</center>"; //displays the next/prev/last links made above
echo "</td>";
echo "</tr>";
?>
</td>
</tr>
</table>
</br>
<span class="nav"><font size="1" face="Verdana"><span class="nav">| <a href="/add.php" title="">Add Your Site</a> | </span></font>
</center>
Css.css
There enjoy i hope i commented enough.Code:body { margin: 24px 0px 24px 0px ; padding: 0px; } .border { border: 1px solid #BBBBBB; } .border-a { border: 1px solid #BBBBBB; background-color: #EEEEEE; } /* Text */ .main { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #333333; line-height: 16px; } .main a:link { text-decoration: underline; color: #0000FF; } .main a:visited { text-decoration: underline; color: #0000FF; } .main a:hover { text-decoration: none; color: #0000FF; } .main a:visited { text-decoration: none; color: #0000FF; } .lighter { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #666666; line-height: 16px; } .lighter a:link { text-decoration: underline; color: #0000FF; } .lighter a:visited { text-decoration: underline; color: #0000FF; } .lighter a:hover { text-decoration: none; color: #0000FF; } .darker { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #222222; line-height: 16px; border: none; } .darker a:link { text-decoration: underline; color: #0000FF; } .darker a:visited { text-decoration: underline; color: #0000FF; } .darker a:hover { text-decoration: none; color: #0000FF; } .large { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 18px; color: #333333; font-weight:bold; line-height: 22px; } .largewhite { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 18px; color: #FFFFFF; font-weight:bold; line-height: 22px; } .medium { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #333333; font-weight:bold; line-height: 22px; } .mediumwhite { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #FFFFFF; font-weight:bold; line-height: 22px; } .small { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #333333; } .small a:link { text-decoration: none; color: #0000FF; } .small a:visited { text-decoration: none; color: #0000FF; } .small a:hover { text-decoration: underline; color: #0000FF; } .nav { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #CCCCCC; } .nav a:link { text-decoration: none; color: #666666; } .nav a:visited { text-decoration: none; color: #666666; } .nav a:hover { text-decoration: none; color: #333333; } .field { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #333333; } .white { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #FFFFFF; } .white a:link { text-decoration: none; color: #FFFFFF; } .white a:visited { text-decoration: none; color: #FFFFFF; } .white a:hover { text-decoration: none; color: #999999; } .italic { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #777777; line-height: 16px; font-style: italic; }






Reply With Quote










