Hey All,
I've been working on this code for three days and it seems like I'm almost there but.....
i found an ok script and i've been trying to make it work with my code.
What happens is I get the "prev 1 2 3 4 5 next" and everything else to display correctly with out a problem on the first page however when I click one of the links I get this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in view.php on line 18
Error: You have an error in your SQL syntax near 'limit 2,2' at line 1
The 'limit 2,2' changes to other numbers like 6,2 but i understand why that is.
Any help would be grand. I'm a NewB so any other comment are welcome.
here is the code for the view.php:
<?
session_start();
$tempcat_name = $GET[cat_name];
$SESSION[cat_id] = $GET[cat_id];
$SESSION[tempcat_name] = $tempcat_name;
$cat_id = $SESSION[cat_id];
$page = $GET[page];
$limit = 2;
$db_name ="alpha";
$connection = mysql_connect("*","","****") or die(mysql_error());
$db = mysql_select_db($db_name,$connection) or die(mysql_error());
$query_count = "SELECT userid, username, company, cat_name, pro_id, pro_name, pro_desc FROM user_table, category, products WHERE user_table.userid = products.user_id AND products.cat_id = category.cat_id AND category.cat_id = $cat_id";
$result_count = mysql_query($query_count);
// Pulls what we want from the database
$totalrows = mysql_num_rows($result_count);
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM user_table, category, products WHERE user_table.userid = products.user_id AND products.cat_id = category.cat_id AND category.cat_id = $cat_id limit $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}
$bgcolor = "#efefef";
while($row3 = mysql_fetch_array($result)){
// Start The Background Check
if($bgcolor == "#e4e4e4"){
$bgcolor = "#efefef";
} else {
$bgcolor = "#e4e4e4";
}
$company = $row3['company'];
$user_id = $row3['user_id'];
$cat_id = $row3['cat_id'];
$cat_name = $row3['cat_name'];
$pro_id = $row3['pro_id'];
$pro_name = $row3['pro_name'];
$pro_desc = $row3['pro_desc'];
$cutpro_desc = substr($pro_desc,0,75);
$option_block .= "<tr bgcolor=$bgcolor><td height=45 valign=top><b>Company: </b>$company<br><b>Product Name: </b><a href=\"viewproduct.php?pro_id=$pro_id\">$pro_name</a> - $cutpro_desc ...</td><td width=5 ><input type=\"checkbox\"></td></tr>";
}
if($page != 1){
$pageprev = $page-1;
echo("<a href=\"$_SERVER[PHP_SELF]?page=$pageprev\">PREV</a> ");
} else {
echo("PREV ");
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++) {
if($i == $page){
echo($i." ");
} else {
echo("<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> ");
}
}
if(($totalrows % $limit) != 0) {
if($i == $page){
echo($i." ");
} else {
echo("<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> ");
}
}
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page +1;
echo("<a href=\"$_SERVER[PHP_SELF]?page=$pagenext\">NEXT</a>");
} else {
echo("NEXT");
}
mysql_free_result($result);
?>
TIA,
troinfo