Hejsa, jeg prøver på at lave en søge maskine til min hjemmeside, men det virker ikke rigtig.
Her er min kode:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<? include('sql.php');
$headquery = mysql_query("SELECT * FROM settings");
while($head = mysql_fetch_array($headquery)) { ?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<META NAME="keywords" CONTENT="<? echo $head['mkeywords']; ?>">
<META NAME="description" CONTENT="<? echo $head['mdescrip']; ?>">
<title><? echo $head['title']; ?></title>
<? } ?>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<center>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="180"><img src="images/header_top.gif" width="180" height="85" alt="" /></td>
<td width="620" background="images/top_bg.gif" class="top"><form id="form1" type="multipart/form-data" method="get" action="index.php"><div>
<img src="images/search_left.gif" width="6" height="23" />
<input type="hidden" name="p" value="search" />
<input name="squery" type="text" id="squery" style="margin-bottom: 4px;" value="Søg..." />
<input type="image" style="width: 24px; height: 23px; border: 0;" value="submit" src="images/search_button.gif" />
</div></form>
</td>
</tr>
<tr>
<td width="180"><img src="images/header_menu.gif" width="180" height="34" alt="" /></td>
<td width="620" align="left" class="menu">
<? include('sql.php');
$menu = mysql_query("SELECT * FROM content WHERE visible = 1 ORDER BY pos ASC");
while($m = mysql_fetch_array($menu)) {
echo "<div id=\\"menu\\"><a href=\\"?p=".$m['id']."\\"><img src=\\"images/menu_bullet.gif\\" alt=\\"\\" width=\\"10\\" height=\\"10\\" border=\\"0\\" /> ".$m['name']."</a></div>"; }
?>
</td>
</tr>
<tr>
<td colspan="2"><img src="images/centerpic.gif" width="800" height="162" alt="" /></td>
</tr>
<tr>
<td colspan="2" background="images/content_bg.gif" bgcolor="#EFEFEF"><div id="sidebar" style="height:100%">
<h1><img src="images/icons/newspaper.png" width="16" height="16" /> Nyheder </h1>
<p>
<? include('sql.php');
$news = mysql_query("SELECT * FROM news ORDER BY id DESC");
while($n = mysql_fetch_array($news)) {
echo "<a href=\\"?p=shownews&newsid=".$n['id']."\\">".substr(strip_tags($n['headline']), 0, 25)."</a>... <br>"; }
?>
<br />
<a href="#"></a>
</div>
<table width="570" border="0" cellpadding="0" cellspacing="0" id="content">
<tr>
<td><? include('sql.php');
$pageid = $_GET['p'];
if($pageid != shownews && $pageid != search) {
if($pageid) {
$content = mysql_query("SELECT * FROM content WHERE id = $pageid");
while($c = mysql_fetch_array($content)) {
echo $c['content']; }}}
elseif(!$pageid) { $content = mysql_query("SELECT * FROM content WHERE pos = 1");
while($c = mysql_fetch_array($content)) {
echo $c['content']; }}
elseif($_GET['p'] == shownews) {
$newsid = $_GET['newsid'];
$getnews = mysql_query("SELECT * FROM news WHERE id = $newsid");
while($r = mysql_fetch_array($getnews)) {
echo "<h2>".$r['headline']."</h2>
<span class=\\"credits\\">Skrevet af ".$r['firstname']." ".$r['lastname']." d. ".$r['date']." </span>
<p>".$r['text']."</p>"; }}
// SEARCHING
if($pageid = search) {
$search = $_POST['squery'];
echo $search;
$keywords = explode(" ", $search);
$searchquery = mysql_query("SELECT * FROM content WHERE content LIKE '%".$keywords['0']."%'");
for ($i=1; $i<count($keywords); $i++) { $searchquery = $searchquery." OR content LIKE '%".$keywords[$i]."%'";
while($s = mysql_fetch_array($searchquery)) {
echo "<a href\\"?p=".$s['id']."<b>".$s['headline']."</b><br />
<span>".substr(strip_tags($s['content']), 0, 200)."...</span>";
}}}
?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2" align="left" class="copyright">© YBnet.dk · Dampmøllegade 11 · 3700 Rønne · Tel: 31 22 63 45 · CVR: 29 59 60 69</td>
</tr>
</table>
</center>
</body>
</html>
Vil rigtig gerne have en løsning på dette problem
På forhånd tak for hjælpe, Christian