473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Please help with correct paging links

osward
38
Hi, everyone,

I had managed to make use of the date link from a simple calendar script to my query table. When I click on the date's link or Prev and Next Month link, The table first row will be that link's day and onwards.

I have a problem with the page link part that it won't advance to the next page according but go back according to today's date.
This is the calender script section[PHP] // Display Calandar
error_reporting('0');
ini_set('display_errors', '0');
// Gather variables from
// user input and break them
// down for usage in our script

if(!isset($_REQUEST['date'])){
$date = mktime(0,0,0,date('m'), date('d'), date('Y'));
} else {
$date = $_REQUEST['date'];
}

$day = date('d', $date);
$month = date('m', $date);
$year = date('Y', $date);

// Get the first day of the month
$month_start = mktime(0,0,0,$month, 1, $year);

// Get friendly month name
$month_name = date('M', $month_start);

// Figure out which day of the week
// the month starts on.
$month_start_day = date('D', $month_start);

switch($month_start_day){
case "Sun": $offset = 0; break;
case "Mon": $offset = 1; break;
case "Tue": $offset = 2; break;
case "Wed": $offset = 3; break;
case "Thu": $offset = 4; break;
case "Fri": $offset = 5; break;
case "Sat": $offset = 6; break;
}

// determine how many days are in the last month.
if($month == 1){
$num_days_last = cal_days_in_month(0, 12, ($year -1));
} else {
$num_days_last = cal_days_in_month(0, ($month -1), $year);
}
// determine how many days are in the current month.
$num_days_current = cal_days_in_month(0, $month, $year);

// Build an array for the current days
// in the month
for($i = 1; $i <= $num_days_current; $i++){
$num_days_array[] = $i;
}

// Build an array for the number of days
// in last month
for($i = 1; $i <= $num_days_last; $i++){
$num_days_last_array[] = $i;
}

// If the $offset from the starting day of the
// week happens to be Sunday, $offset would be 0,
// so don't need an offset correction.

if($offset > 0){
$offset_correction = array_slice($num_days_last_array, -$offset, $offset);
$new_count = array_merge($offset_correction, $num_days_array);
$offset_count = count($offset_correction);
} else {
// The else statement is to prevent building the $offset array.
$offset_count = 0;
$new_count = $num_days_array;
}

// count how many days we have with the two
// previous arrays merged together
$current_num = count($new_count);

// Since we will have 5 HTML table rows (TR)
// with 7 table data entries (TD)
// we need to fill in 35 TDs
// so, we will have to figure out
// how many days to appened to the end
// of the final array to make it 35 days.

if($current_num > 35){
$num_weeks = 6;
$outset = (42 - $current_num);
} elseif($current_num < 35){
$num_weeks = 5;
$outset = (35 - $current_num);
}
if($current_num == 35){
$num_weeks = 5;
$outset = 0;
}
// Outset Correction
for($i = 1; $i <= $outset; $i++){
$new_count[] = $i;
}

// Now let's "chunk" the $all_days array
// into weeks. Each week has 7 days
// so we will array_chunk it into 7 days.
$weeks = array_chunk($new_count, 7);

// Build Previous and Next Links
$previous_link = "<a href=\"/modules.php?name=event&date=";
if($month == 1){
$previous_link .= mktime(0,0,0,12,$day,($year -1));
} else {
$previous_link .= mktime(0,0,0,($month -1),$day,$year);
}
$previous_link .= "\"><< "._PREVMON."</a>";

$next_link = "<a href=\"/modules.php?name=event&date=";
if($month == 12){
$next_link .= mktime(0,0,0,1,$day,($year + 1));
} else {
$next_link .= mktime(0,0,0,($month +1),$day,$year);
}
$next_link .= "\">"._NEXTMON." >></a>";

// Build the heading portion of the calendar table
echo "<center>";
echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\" width=\"300\" class=\"calendar\">\n".
"<tr>\n".
"<td colspan=\"7\">\n".
"<table align=\"center\">\n".
"<tr>\n".
"<td colspan=\"2\" width=\"75\" align=\"left\">$previous_link</td>\n".
"<td colspan=\"3\" width=\"150\" align=\"center\">$month_name $year</td>\n".
"<td colspan=\"2\" width=\"75\" align=\"right\">$next_link</td>\n".
"</tr>\n".
"</table>\n".
"</td>\n".
"<tr bgcolor=\"$bgcolor2\">\n".
"<td>S</td><td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td>\n".
"</tr>\n";

// Now we break each key of the array
// into a week and create a new table row for each
// week with the days of that week in the table data

$i = 0;
foreach($weeks AS $week){
echo "<tr>\n";
foreach($week as $d){
if($i < $offset_count){
$day_link = "<a href=\"modules.php?name=event&date=".mktime(0,0,0, $month -1,$d,$year)."\">$d</a>";
echo "<td class=\"nonmonthdays\">$day_link</td>\n";
}
if(($i >= $offset_count) && ($i < ($num_weeks * 7) - $outset)){
$day_link = "<a href=\"modules.php?name=event&date=".mktime(0,0,0, $month,$d,$year)."\">$d</a>";
if($date == mktime(0,0,0,$month,$d,$year)){
echo "<td class=\"today\">$d</td>\n";
} else {
echo "<td class=\"days\">$day_link</td>\n";
}
} elseif(($outset > 0)) {
if(($i >= ($num_weeks * 7) - $outset)){
$day_link = "<a href=\"modules.php?name=event&date=".mktime(0,0,0, $month +1,$d,$year)."\">$d</a>";
echo "<td class=\"nonmonthdays\">$day_link</td>\n";
}
}
$i++;
}
echo "</tr>\n";
}

// Close out your table and that's it!
echo '<tr><td colspan="7" class="days"> </td></tr>';
echo '</table></center>';
echo "<br>";[/PHP]This is my query to the database table[PHP] // sort table colum
$sort_order = 'date asc';
if( isset( $_GET['order']) ){
$order = $_GET['order'];
switch ($order) {
case "A_date":
$sort_oredr = 'date asc';
break;
case "D_date":
$sort_order = 'date desc';
break;
case "A_place":
$sort_order = 'place asc';
break;
case "D_place":
$sort_order = 'place desc';
break;
}
}

$d = date("Y-m-d", $date); // this will return today's date as calendar
$where_field = "date >= '$d'";

// Set max number of row for Paging tableORDER by".$sort_order."
$max_results = 15;
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
$from = (($page * $max_results) - $max_results);
$result = $db->sql_query("SELECT * FROM ".$prefix."_event_cat WHERE $where_field ORDER by $sort_order LIMIT $from, $max_results") or die("Error: " . $db->sql_error());
if($db->sql_numrows($result) == 0){
echo(""._NODATA."");
}[/PHP]and finally this is my paging link section[PHP] // Page Numbering
$total_results = mysql_result($db->sql_query("SELECT COUNT(*) as date FROM ".$prefix."_event_cat WHERE $where_field"),0);
$total_pages = ceil($total_results / $max_results);
$sort_order = $_GET['order'];
// Build Previous Link
echo "<center>";
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"/modules.php?name=event&page=1&order=$sort_order\"> <img src=\"images/dl_arrow.gif\" alt=\""._FIRST."\" title=\""._FIRST."\" border=\"0\"></a> ";
echo " <a href=\"/modules.php?name=event&page=$prev&order=$sort_orde r\"><img src=\"images/l_arrow.gif\" alt=\""._PREV."\" title=\""._PREV."\" border=\"0\"></a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "&nbsp;[$i]&nbsp;";
} else {
echo "<a href=\"/modules.php?name=event&page=$i&order=$sort_order\" >&nbsp;$i&nbsp;</a> ";
}
}
// Build Next & Last page Link
if($page < $total_pages){
$next = ($page + 1);
echo " <a href=\"/modules.php?name=event&page=$next&order=$sort_orde r\"><img src=\"images/r_arrow.gif\" alt=\""._NEXT."\" title=\""._NEXT."\" border=\"0\"></a> ";
$last = $total_pages;
echo " <a href=\"/modules.php?name=event&page=$last&order=$sort_orde r\"><img src=\"images/dr_arrow.gif\" alt=\""._LASTPAGE."\" title=\""._LASTPAGE."\" border=\"0\"></a>";
}
echo "</center>";
echo "<br>";[/PHP]
line 106 of the 1st section of code : is the link created by the calendar script
line 21 of the 2nd section of code : is where I define and convert the date to put into the query

Please help me to make the paging link work along with the date link from the calendar.

Also I would like to have the calendar go along with the page link when the page advance to the next month, the calender would change to the next month accordingly.

Thanks in advance
Nov 6 '07 #1
3 2018
pbmods
5,821 Expert 4TB
Heya, Osward.

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Nov 6 '07 #2
osward
38
Heya, Osward.

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Hi, pbmods

What I had achieve is:
using the link in the calendar that my table can display the row necessary. ie, If I click September 3, 2007, The query returns September 3, 2007 and rows onward.

What I don't want it to do is:
if user click the Next page as the above had been returened. It display the 2nd page of the default query. That is, SELECT * FROM mydb_tbl $where_field.
The var $where_field is define on line 21,22 of my 2nd portion of the code posted
which $date is from line 9, of the calender code

What I want to do is:
The page will display the 2nd page of page starting from September 3, 2007. Also as the page moves forward, the calander display will follow as well. If the follow of calender display is too much of a trouble, I can live with it but I definitely need the page move forward correctly
Nov 8 '07 #3
osward
38
In addition to my yesterday's post. I follow the method to maintain the sort_order in my previous post. I think I have to $_GET(date) from the url that add date=$where_field to the page link. There are 2 problems that I immediately encounter.

1. I had already use the $date to convert to $t = date("Y-m-d", $date) and put it in my $where_field for the start of any query to the database, which was fine to start with. The problem is if I add date=$where_field at the page link, it returns the 2007-11-09, not unix timestamp. (Think I can convert back to unix timestamp before subsistue back to the link)

2. I had to make the $where_field return a unix timestamp to date= $where_field that is equal to the number of rows to display per page (assume one day a row of display), and the increment of the value of limited rows per page at the link, and so on. ie, page link would be &page=$i&date=$where_field
example:
limit rows per page $limit_rows = 15
$date = mktime(0,0,0,11,01,2007) - the initial query date or date from the url
The 1st $where_field = mktime(0,0,0,11,01+(1*15),2007)
The 2nd $where_field = mktime(0,0,0,11,01+(2*15),2007)
In (1*15), 1 is number of page which should be $i, 15 is the no.of rows to limit
If I put $where_field = mktime(0,0,0,date('m'),date('d'+($i*$limit_rows),d ate('y'))
All the subsquence page links display the 1st increment but not loop through like $i
I am not sure how I could make this happens

Any help would be greatly appreciated

Thanks in advance
Nov 9 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mark | last post by:
I need some advice on how to acheive the desired result of my custom page link generation. The datagrid 'built-in' page navigation only allows either the 'Prev/Next' or the page numbers. ...
1
by: Adam Clauss | last post by:
Alright, this is the first time I've attempted to use a datagrid (in ASP.NET or otherwise). I set to true the properties for AllowPaging and AllowSorting. So now on the page, I get the first...
1
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has...
2
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
8
by: Greg Lyles | last post by:
Hi all, I'm trying to develop an ASP.NET 2.0 website and am running into some real problems with what I thought would be a relatively simple thing to do. In a nutshell, I'm stuck on trying to...
6
khalidbaloch
by: khalidbaloch | last post by:
can any one help me creating a dynamic pagination script for non-sql entries i made this simple paging script <?php //Show Result Per Page $ResultPerPage=10; //Total Result Availaible...
1
by: rbrowning1958 | last post by:
Hello, I wonder whether someone can explain to me how data is fetched from a database server when using ASP.NET 2.0's gridview with paging enabled? My SQL DataSource has a simple "select * from...
8
tharden3
by: tharden3 | last post by:
Hey all, I need some help with PHP code for paging my products on my site. I posted questions asking for help in the past, and was directed to this tutorial for help. The code that the tutorial gives...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.