Pagenation with a default value like today's
Posted: Fri Jan 14, 2005 10:15 pm
Is it possible for a pagenation script to default to certain date evertime it is called? I tried using where date = $today but then then script will not work. The script works but defaults to the first record everytime. I would like to show the current date's record and allow the previous function to still work. Thanks.
feyd | please use formatting!
Code: Select all
<?
$today = getdate();
$day = $today;
$db_username = "xxxxxxxxx"; // username for database here
$db_password = "xxxxxxxxx"; // password for database here
$db_name = "xxxxxxxxx"; // name of your database here
$mysql_link = mysql_connect( "xxxxxxxxxxx", "$db_username", "$db_password") or die( "Unable to connect to database server");
@mysql_select_db( "$db_name") or die( "Unable to select database");
function recordsetNav(&$db_connect,$db_query,$page_url,$offset=0,$limit=0,$tablewidth='100%',$verbiage=1,$extraurl='',$blocksize=1)
{
/*
EXAMPLE USAGE: recordsetNav($mysql_link,$extended_horoscopes_query,$PHP_SELF,$offset,$limit,'75%',0,$extraurl,$blocksize);
&$db_connect is the MySQL connection passed by reference
$db_query is your entire query string including WHERE criteria and ORDER BY - without the LIMIT statement!
$page_url will probably be $PHP_SELF
$tablewidth determines the width of the $navstring table
$verbiage, by default set to 'true', prints out "page:$pagenumber/$totalpages total records:$totalrecords"
$extraurl extra variables passed in the URL e.g. $extraurl="&findfield=$findfield&findvalue=$findvalue"
$blocksize, by default set to 15, determines how many page links to display
*/
$db_result = @mysql_query($db_query,$db_connect);
$totalrecords = @mysql_num_rows($db_result);
$pagenumber = intval(($offset + $limit) / $limit);
$totalpages = intval($totalrecords/$limit);
if ($totalrecords%$limit > 0) // partial page
{
$lastpage = $totalpages * $limit;
$totalpages++;
} else {
$lastpage = ($totalpages - 1) * $limit;
}
// start building navigation string
$navstring = "<table width="$tablewidth" cellspacing="0" cellpadding="1" border="0">";
if ($totalrecords > $limit) // only show <<PREV NEXT>> row if $totalrecords is greater than $limit
{
$navstring .= "<tr>";
$navstring .= "<td align='center'>";
if ($offset != 0)
{
$navstring .= "<a title='Previous Day' href='".$page_url."?offset=".($offset-$limit)."$extraurl'><b>Previous Day</a></b> ";
$navstring .= "<a title='First Page' href='".$page_url."?offset=0$extraurl'><b>Today</a></b> ";
}
if ($totalpages < $blocksize)
{
$blocksize = $totalpages;
$firstpage = 1;
} elseif ($pagenumber > $blocksize) {
$firstpage = ($pagenumber-$blocksize) + 2;
} elseif ($pagenumber == $blocksize) {
$firstpage = 2;
} else {
$firstpage = 1;
}
$blocklimit = $blocksize + $firstpage;
if($totalrecords-$offset > $limit)
{
$navstring .= " <a title='Next Day' class='MENUsmall' href='".$page_url."?offset=".($offset+$limit)."$extraurl'><b>Next Day</b></a> ";
}
$navstring .= "</td></tr>";
}
$navstring .= "</table>";
echo $navstring;
}
?>
<!-- HTML -->
<head>
<title>Test</title>
</head>
<body>
<p>
<?
if (!isset($offset)) $offset = 0;
$limit = 1; // this detemines max records per page
$extended_horoscopes_query = "SELECT * FROM extended_horoscopes ORDER BY date ASC";
$extended_horoscopes_limit = " LIMIT " . $offset . "," . $limit;
$extended_horoscopes_display = @mysql_query($extended_horoscopes_query.$extended_horoscopes_limit) or die ("ERROR: The query failed.");
// table header
echo "<table align='center' width='100%' cellspacing='1' cellpadding='1' border='1'>";
echo "<tr></tr>";
// table body
while ($row = @mysql_fetch_array($extended_horoscopes_display))
{
$id = $rowї"id"];
$date = $rowї"date"];
$aries = $rowї"aries"];
echo "<tr><td>Daily Extended for Aries for $date</td><tr></tr><td>$aries</td></tr>";
}
// table footer
echo "<tfoot>";
echo "<tr><td align="center" colspan="5">";
echo "</td></tr></tfoot></table>";
recordsetNav($mysql_link,$extended_horoscopes_query,$PHP_SELF,$offset,$limit,'100%',1);
@mysql_close($mysql_link);
?>
<table>
<tr>
</tr>
</table>
</body>
</html>feyd | please use formatting!