Code: Select all
$result = mysql_query ("SELECT * FROM products WHERE category = '$mycateg' AND stockstatus= 'in stock' ORDER BY title LIMIT $offset, $rowsPerPage") or die (mysql_error());stockstatus, and ORDER BY
Moderator: General Moderators
Code: Select all
$result = mysql_query ("SELECT * FROM products WHERE category = '$mycateg' AND stockstatus= 'in stock' ORDER BY title LIMIT $offset, $rowsPerPage") or die (mysql_error());As in, echo the query and copy the output here.What does your query look like? Not in the script, the actual query that is sent to the DB.
Without the query outputted, I get blank.SELECT * FROM products WHERE category = 'Accessories' AND stockstatus= 'in stock' ORDER BY title LIMIT 0, 20
No offset.....??SELECT * FROM products WHERE category = 'Accessories' AND stockstatus= 'in stock' ORDER BY title LIMIT , You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Code: Select all
<?php
$mycateg = $_REQUEST['category'];
echo "<div class='categorytitle'>$mycateg</div>";
include "dbconn.php";
$result = mysql_query ("SELECT * FROM products WHERE cat = 'yes' AND category = '$mycateg'");
while ($row = mysql_fetch_object($result))
{
echo "
<div class='categorypromotionbox'>
<div class='producttitle'>$row->title";
$cookieuser = $_COOKIE['user'];
if (isset($_COOKIE['user'])) { echo "
<form method='post' action='index.php?page=a_productedit&menu=a_productshelp'>
<input type='hidden' name='id' value='$row->id'>
<input type='submit' value='Edit' class='submittext'>
</form>";
}
echo "</div>
<div class='productimage'>
<a href='index.php?page=product&menu=categ&category=$row->category&product=$row->id'><img src='images/productphotos/$row->photoprimary' border='0' title='$row->title' ></a></div>
<div class='productdescription'>";
$position=320; //Defines how many characters will be displayed from content field.
$postcontent = substr($row->description,0,$position);
echo "$postcontent...<i>continued</i>...</div>
<div class='productbuynow'><font color='#ff0000'>ONLY £$row->price</font> | ";
if ($row->stockstatus == "in stock") { echo "$row->cartbutton"; }
elseif ($row->stockstatus == "sold out") { echo "Sorry, sold out."; }
echo "</font></div>
";
}
mysql_free_result($result);
echo "</div><img src='images/header_longblank.gif' style='margin-top:10px'/>";
// how many rows to show per page
$rowsPerPage = 20;
// by default we show first page
$pageNum = 1;
// if $_GET['pagenum'] defined, use it as page number
if(isset($_GET['pagenum']))
{
$pageNum = $_GET['pagenum'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
echo "SELECT * FROM products WHERE category = '$mycateg' AND stockstatus= 'in stock' ORDER BY title LIMIT $offset, $rowsPerPage";
$result = mysql_query ("SELECT * FROM products WHERE category = '$mycateg' AND stockstatus= 'in stock' ORDER BY title LIMIT $offset, $rowsPerPage") or die (mysql_error());
while ($row = mysql_fetch_object($result))
{
echo "
<div class='cat_prodlistbox'>
<div class='cat_producttitle'>";
$cookieuser = $_COOKIE['user'];
if (isset($_COOKIE['user'])) { echo "<div style='width:20px; float:right'>
<form method='post' action='index.php?page=a_productedit&menu=a_productshelp'>
<input type='hidden' name='id' value='$row->id'>
<input type='submit' value='Edit' class='submittext'>
</form></div>";
}
echo $row['title'] . "</div>
<a href='index.php?page=product&menu=categ&category=$mycateg&product=". $row['id'] . " title='Look at the ". $row['title'] ."><img src='images/productphotos/" . $row['photoprimary'] ."' border='0' /></a><br/>";
echo "£". $row['price'] ."</div>";
}
$query = "SELECT COUNT(id) AS numrows FROM products";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"index.php?page=categ&menu=categ&category=$mycateg&pagenum=$page\">$pagenum</a> ";
}
}
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"index.php?page=categ&menu=categ&category=$mycateg&pagenum=$page\">[Prev]</a> ";
$first = " <a href=\"index.php?page=categ&menu=categ&category=$mycateg&pagenum=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"index.php?page=categ&menu=categ&category=$mycateg&pagenum=$page\">[Next]</a> ";
$last = " <a href=\"index.php?page=categ&menu=categ&category=$mycateg&pagenum=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $first . $prev . $nav . $next . $last;
mysql_close($sqlconn);
?>Code: Select all
error_reporting(E_ALL);Code: Select all
error_reporting(-1);Code: Select all
error_reporting = E_STRICTCode: Select all
<?php
phpinfo();
?>Fatal error: Cannot use object of type stdClass as array in C:\xampp\phpmyadmin\company\includes\categ.inc on line 76
Code: Select all
<a href='index.php?page=product&menu=categ&category=$mycateg&product=". $row['id'] . " title='Look at the ". $row['title'] ."><img src='images/productphotos/" . $row['photoprimary'] ."' border='0' /></a><br/>";