Page 1 of 1

Pagenation with a default value like today's

Posted: Fri Jan 14, 2005 10:15 pm
by idribble
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.

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)
&#123;
	/*
	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
	&#123;
		$lastpage = $totalpages * $limit;
		$totalpages++;
	&#125; else &#123;
		$lastpage = ($totalpages - 1) * $limit;
	&#125;
		
	// 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
	&#123;
		$navstring .= "<tr>";
		$navstring .= "<td align='center'>";
		if ($offset != 0)
		&#123;
			$navstring .= "<a title='Previous Day' href='".$page_url."?offset=".($offset-$limit)."$extraurl'><b>Previous Day</a></b>&nbsp;&nbsp;";
			$navstring .= "<a title='First Page' href='".$page_url."?offset=0$extraurl'><b>Today</a></b> &nbsp;";
		&#125;
		
		if ($totalpages < $blocksize)
		&#123;
			$blocksize = $totalpages;
			$firstpage = 1;
		&#125; elseif ($pagenumber > $blocksize) &#123;
			$firstpage = ($pagenumber-$blocksize) + 2;
		&#125; elseif ($pagenumber == $blocksize) &#123;
			$firstpage = 2;
		&#125; else &#123;
			$firstpage = 1;
		&#125;
		
		$blocklimit = $blocksize + $firstpage;
		
				
		if($totalrecords-$offset > $limit)
		&#123; 
			$navstring .= "&nbsp;<a title='Next Day' class='MENUsmall' href='".$page_url."?offset=".($offset+$limit)."$extraurl'><b>Next Day</b></a> &nbsp;"; 
		&#125;
		$navstring .= "</td></tr>";
	&#125;	
	
	
	$navstring .= "</table>";
	
	echo $navstring;
&#125;


?>

<!-- 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))
&#123;
	$id = $row&#1111;"id"];
	$date = $row&#1111;"date"];
	$aries = $row&#1111;"aries"];
	
	echo "<tr><td>Daily Extended for Aries for $date</td><tr></tr><td>$aries</td></tr>";
&#125;

// 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!

Posted: Fri Jan 14, 2005 10:31 pm
by rehfeld
getdate() returns an array, not a string or integer