Hi!
Well, it took me a while, and i've been trying to isolate the problem, but can't find the answer. Here's some code, first part searches for matches, whether it be categorised or not. After that some includes, one for category, one for entire database. These are used for pagination. But things go wrong before that. I've been trying to structure the code, so that there wouldn't be duplicate <body>'s and <html>'s, so that ouput would be like:
<html>
<body>
<? script stuff; ?>
<body>
<html>
All the code might not be perfect, since i'm fairly new to PHP, so...
thanks in advance
thefisherman
<?php
/////////////// Start the session ///////////////
session_start();
$dis=session_id();
include ("ol.php");
/////////////////// Variables ///////////////////
if (!isset($start)) {
$start=0;
}
if (!isset($page)) {
$page=1;
}
if (isset($resultset)) {
mysql_free_result($resultset);
}
if (isset($num_rows_total)) {
mysql_free_result($num_rows_total);
}
if (isset($SQL_statement)) {
mysql_free_result($SQL_statement);
}
if (isset($num_rows)) {
mysql_free_result($num_rows_total);
}
if (isset($data)) {
mysql_free_result($data);
}
$limiet=10;
$imagepath="database11";
////////////////////////////////////////////////
include "ConnectDB11.php";
$start=($page-1)*$limiet;
"</br>";
/////////////// Get results from the Database ///////////////
if (!isset($catego)) {
$SQL_statement_total = "SELECT * FROM maintable WHERE description LIKE '%$keyword%'";
$resultset_total = mysql_query($SQL_statement_total);
$num_rows_total = mysql_num_rows($resultset_total);
} else {
$getcatnumber = "SELECT * from cat where cat='$catego'";
$getcatnumberresult = mysql_query($getcatnumber);
$catnumber_result = mysql_fetch_array($getcatnumberresult);
$detectnumber=$catnumber_result['cat_id'];
$SQL_statement_total = "SELECT * FROM maintable WHERE description LIKE '%$keyword%' AND cat_id='$detectnumber'";
$resultset_total = mysql_query($SQL_statement_total);
$num_rows_total = mysql_num_rows($resultset_total);
}
////// Check if a category was chosen ////////
if (!isset($catego)) {
$SQL_statement = "SELECT * FROM maintable WHERE description LIKE '%$keyword%' LIMIT " . $start . "," . $limiet;
} else {
/// If so.... ///
$getcatnumber = "SELECT * from cat where cat='$catego'";
$getcatnumberresult = mysql_query($getcatnumber);
$catnumber_result = mysql_fetch_array($getcatnumberresult);
$detectnumber=$catnumber_result['cat_id'];
$SQL_statement = "SELECT * FROM maintable WHERE description LIKE '%$keyword%' AND cat_id='$detectnumber' ORDER BY author, id LIMIT " . $start . "," . $limiet;
}
$resultset = mysql_query($SQL_statement);
$num_rows = mysql_num_rows($resultset);
//// If results are less than 1, do something ////
if ($num_rows<1) {
include ("notfound.htm");
}
else {
//// Otherwise, setup variables and display stuff ////
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body BGCOLOR=#990000 text="#FFFFFF" link="#FF9900" vlink="#666666" alink="#FF6600">
<table width="100%" border="0">
<tr>
<td align="center" bgcolor="#000000"><div align="left"><img src="search_result.jpg" width="188" height="35"></div></td>
<td align="center" bgcolor="#000000"><div align="center"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">
<?php include ("du.php");?>
</font></div></td>
</tr>
</table>
<?
include ("ConnectDB11.php");
while ($data = mysql_fetch_array($resultset)){
$imagefile=$data['filename'];
$catnum=$data['cat_id'];
$idnum=$data['id'];
$cat_statement = "SELECT * from cat WHERE cat_id = '$catnum'";
$cat_result = mysql_query($cat_statement);
$cat_name = mysql_fetch_array($cat_result);
$sizenum=$data['size_id'];
$size_statement = "SELECT * from size WHERE size_id = '$sizenum'";
$size_result = mysql_query($size_statement);
$size_name = mysql_fetch_array($size_result);
$resnum=$data['res_id'];
$res_statement = "SELECT * from res WHERE res_id = '$resnum'";
$res_result = mysql_query($res_statement);
$res_name = mysql_fetch_array($res_result);
$pricenum=$data['price_id'];
$price_statement = "SELECT * from price WHERE price_id = '$pricenum'";
$price_result = mysql_query($price_statement);
$price_name = mysql_fetch_array($price_result);
$imagetotal = "<img src = $imagepath/$imagefile>";
// include ("template.php");
?>
<table width="100%" border="0" cellpadding="0" cellspacing="10" bordercolor="#FFFFFF">
<tr>
<td width="35%" bordercolor="#FFFFFF"><? print($imagetotal);?></td>
<td width="55%"> <font size="1" face="Geneva, Arial, Helvetica, sans-serif">
<? echo "<li>Description: " . $data['description'] . "";?> <? echo "<li>Size in CM: " . $size_name['size'] . "";?>
<? echo "<li>Resolution: " . $res_name['res'] . "";?> <? echo "<li>Preview-filename: " . $data['filename'] . "";?>
<? echo "<li>Category: " . $cat_name['cat'] . "";?> <? echo "<li>Price: € " . $price_name['price'] . "";?>
<? echo "<li>Photograph number: " . $idnum . "";?> <? echo "<li>Author: " . $data['author'] . "";?>
</td>
<td width="10%" align="left" nowrap><div align="center"> <img src="cart2.gif" width="32" height="32" border="0"><br>
<?
if(isset($catego)){echo "<a href='add_to_cart.php?imagekey=".$idnum."&page=".$page."&keyword=".$keyword."&catego=".$catego."&detectnumber=".$detectnumber."'>Add to cart</a>";
}else{echo "<a href='add_to_cart.php?imagekey=".$idnum."&page=".$page."&keyword=".$keyword."'>Add to cart</font></a>";
}
?>
</div></td>
</tr>
</table>
<hr>
<?
}
}
//// Set the navigation below the page ////
if (!isset($catego)) {
include ("template_nav.htm");
} else {
include ("template_navcat.htm");
}
?>
// Here's the nav-part (without category chosen):
<? session_start();
$dis=session_id();
$server = "localhost";
$username = "xxxxxxx";
$password = "xxxxxxxxxxxx";
$database = "xxxxx";
$table = "maintable";
$pagelimit = "10";
$pagenums = ceil ($num_rows_total/$pagelimit);
if ($page==''){
$page='1';
}
$start = ($page-1) * $pagelimit;
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center">
<?
echo "<b>" . $num_rows_total . " matches found</b><br>\n";
$starting_no = $start + 1;
if ($num_rows_total - $start < $pagelimit) {
$end_count = $totalrows;
} elseif ($num_rows_total - $start >= $pagelimit) {
$end_count = $start + $pagelimit;
}
echo "Results $starting_no to $end_count shown.<br>\n";
if ($num_rows_total - $end_count > $pagelimit) {
$var2 = $pagelimit;
} elseif ($num_rows_total - $end_count <= $pagelimit) {
$var2 = $num_rows_total - $end_count;
}
$space = " ";
if ($page>1) {
echo " <a href='authenticate11.php?page=".($page-1)."&keyword=".$keyword."' class=main>Previous" . $space . $pagelimit . "</a>" . $space . $space . "";
}
if ($page<$pagenums) {
echo "" . $space . $space . $space . $space . " <a href='authenticate11.php?page=".($page+1)."&keyword=".$keyword."' class=main>Next " . $var2 . "</a> ";
}
$strSQL = mysql_query("SELECT * FROM $maintable LIMIT $start,$pagelimit");
?>
</div>
</td>
</tr>
</table>
</body>
</html>
// And the nav-part with category chosen:
<? session_start();
$dis=session_id();
$server = "localhost";
$username = "xxxx";
$password = "xxxxxxxxx";
$database = "xxxxxxxxx";
$table = "maintable";
$pagelimit = "10";
$pagenums = ceil ($num_rows_total/$pagelimit);
if ($page==''){
$page='1';
}
$start = ($page-1) * $pagelimit;
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center">
<?
echo "<b>" . $num_rows_total . " matches found</b><br>\n";
$starting_no = $start + 1;
if ($num_rows_total - $start < $pagelimit) {
$end_count = $num_rows_total;
} elseif ($num_rows_total - $start >= $pagelimit) {
$end_count = $start + $pagelimit;
}
echo "Results $starting_no to $end_count shown.<br>\n";
if ($num_rows_total - $end_count > $pagelimit) {
$var2 = $pagelimit;
} elseif ($num_rows_total - $end_count <= $pagelimit) {
$var2 = $num_rows_total - $end_count;
}
$space = " ";
if ($page>1) {
echo " <a href='authenticate11.php?page=".($page-1)."&keyword=".$keyword."&catego=".$catego."&detectnumber=".$detectnumber."' class=main>Previous" . $space . $pagelimit . "</a>" . $space . $space . "";
}
if ($page<$pagenums) {
echo "" . $space . $space . $space . $space . " <a href='authenticate11.php?page=".($page+1)."&keyword=".$keyword."&catego=".$catego."&detectnumber=".$detectnumber."' class=main>Next " . $var2 . "</a> ";
}
?>
</div>
</td>
</tr>
</table>
</body>
</html>
// It's quite a lot i know....