[liphp] Next Page Help
Troy Thomas
[email protected]
15 Oct 2003 12:26:07 -0400
Hey All,
I hope someone can help me.
I've been trying to get this <prev 1 2 3 next> code that I got off
phpbuilder.com working with my code and it works fine until you click on
one of the links.
When i click the links I do not get the rest of the results from the
record set.
Please understand I'm still a novice at this stuff, pretty surprised I
got it working this far :).
Here is the code:
-------------------------------
<?
// ------ MY CODE ------ //
session_start();
$tdcolor == 0;
$tempcat_name = $_GET[cat_name];
$_SESSION[cat_id] = $_GET[cat_id];
$_SESSION[tempcat_name] = $tempcat_name;
$cat_id = $_SESSION[cat_id];
$db_name ="alpha";
$connection = mysql_connect("******","******","******") or
die(mysql_error());
$db = mysql_select_db($db_name,$connection)or die(mysql_error());
$sql3 = "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 = $_SESSION[cat_id] ";
//echo $sql3;
$result3 = mysql_query($sql3,$connection) or die(mysql_error());
$num = mysql_num_rows($result3);
if ($num < 1) {
//if there are no results,display message
$option_block = "<P><em>Sorry! No results under this category yet check
back soon. Thank you.</em></p>";
} else {
// ------ END MY CODE ------ //
$recordLimit= 5; // Limit per page
/*==Font control for the
/Prev Naviagation==*/
$prevStatus = "Show Previous $recordLimit Results";
$nextStatus = "Show Next $recordLimit Results";
$prevLink = "< Previous|";
$nextLink = "|Next >";
$fontfamily = "tahoma, helvetica";
$fontsize = "13px";
$fontcolor = "#000000";
$inactivecolor = "#666666"; // Color for when there is no link
$fontweight = "700";
$textdecoration = "none";
/*==If thisOffset not set, set to zero==============*/
if (!isset($thisOffset) || $thisOffset < 0) $thisOffset=0;
if ($action==search) $thisOffset = $thisOffset - 1;
/*==This is to count the line index of the results==*/
/*=============if not set, set to zero==============*/
if (!isset($lineIndex) || $lineIndex < 0) $lineIndex=0;
if ($action==search) $lineIndex = $lineIndex - 1;
/*==Query for the total number of rows==*/
$getTotalRows = mysql_query($sql3, $connection);
$totalRowsNum = mysql_num_rows($getTotalRows);
/*==Append the limit and offset to the sql==*/
$sql3.=" Limit $thisOffset,$recordLimit";
/*==Query and fetch array with the limit and offset==*/
$query = mysql_query($sql3, $connection);
while ($row3=mysql_fetch_array($query)){
/*==Increment the line index by 1==*/
$lineIndex++;
/*====== Your results layout goes here =======*/
// ------ MY CODE ------ //
if ($tdcolor == 0) {
$color = "#efefef";
$tdcolor = 1;
} else {
$color = "#e4e4e4";
$tdcolor = 0;
}
$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=$color><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>";
}
// ------ END MY CODE ------ //
/*==If the number of returned is less than the limit, show nothing===*/
if ($totalRowsNum <= $recordLimit) {
// less than recordLimit returned.
} else {
/*==If the current offset is not equal to zero==*/
/*==Show the link. Else (if>0) show just text===*/
if ($thisOffset!=0) { $prevOffset = intval($thisOffset-$recordLimit);
$page_count = "<a style='font-family:$fontfamily; font-size:$fontsize;
color:$fontcolor; font-weight:$fontweight;"
." text-decoration:$textdecoration;'
onmouseover=\"window.status='$prevStatus'; return true\""
." onmouseout=\"window.status=''\"
href=\"$PHP_SELF?thisOffset=$prevOffset&lineIndex=$prevOffset\">"
."$prevLink</a> ";
}
else { $page_count = "<span style='font-family:$fontfamily;
font-size:$fontsize; color:$inactivecolor;"
." font-weight:$fontweight;
text-decoration:$textdecoration;'>$prevLink</span> ";
}
/*==Divide total rows by record limit to get the number of pages==*/
$totalPages = intval($totalRowsNum/$recordLimit);
/*==If remainder is left from division increment totalPages==*/
if ($totalRowsNum%$recordLimit) $totalPages++;
/*==Using a for() loop, Display links for each page. 1 2 3==*/
for ($i=1;$i<=$totalPages;$i++) {
/*==If the page being viewed is the current page, disable the link==*/
if ((intval($thisOffset/$recordLimit)) == (intval($i-1))) {
$page_count .= " <span style='font-family:$fontfamily;
font-size:$fontsize; color:$inactivecolor;"
." font-weight:$fontweight;
text-decoration:$textdecoration;'>$i</span> ";
} else {
/*==If not current page, set nextOffset and display link==*/
$nextOffset= intval($recordLimit*($i-1));
$page_count .= " <a style='font-family:$fontfamily;
font-size:$fontsize; color:$fontcolor;"
." font-weight:$fontweight; text-decoration:$textdecoration;'
onmouseover=\"window.status='";
//pageStatus($i);
$page_count .= "'; return true\" onmouseout=\"window.status=''\""
."
href=\"$PHP_SELF?cat_id=$_SESSION[cat_id]&thisOffset=$nextOffset&lineIndex=$nextOffset\">$i</a> ";
}
}
/*==If the page is not the last page, set the nextOffset and show the
link==*/
/*==============If the page is the last page disable the
link===============*/
if (!(intval(((intval($thisOffset/$recordLimit))+1))==$totalPages) &&
$totalPages!=1) {
$nextOffset = intval($thisOffset+$recordLimit);
$page_count .= " <a style='font-family:$fontfamily;
font-size:$fontsize; color:$fontcolor; font-weight:$fontweight;"
." text-decoration:$textdecoration;'
onmouseover=\"window.status='$nextStatus'; return true\""
." onmouseout=\"window.status=''\"
href=\"$PHP_SELF?cat_id=$_SESSION[cat_id]&thisOffset=$nextOffset&lineIndex=$nextOffset\">$nextLink</a><p>\n";
} else
$page_count .= " "
."<span style='font-family:$fontfamily; font-size:$fontsize;
color:$inactivecolor;"
." font-weight:$fontweight;
text-decoration:$textdecoration;'>$nextLink</span><p>";
}
mysql_close($connection);
//End
}
?>
-------------------------------
TIA,
Troy
--
"Which brings us at last to the moment of truth
where in the fundamental flaw is ultimately expressed
and the anomaly revealed as both the beginning and end."