473,320 Members | 2,111 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,320 software developers and data experts.

Help with Previous and Next links and Displaying Database information

I would like to display a listing of files on a web page as follows:

If there is only one file: display the section name and then display the
current file.

If there is more than one file (for the first page): display the section
name, the current file and a few archive files.

If there is more than a page full (for each additional page): display the
section name, and the next set of archive files.

This is the code I have been working with (it's a bit ugly, suggestions are
welcome). For some reason the second page of listings skips the first item.
1st page lists items 0 through 4, second page skips item 5 and starts
displaying item 6.

Thanks,

-Mark

function display_table($sec_id, $num_item){
GLOBAL $link;
$updir = "../uploads/"; //maybe this should be a GLOBAL variable???
if (isset($_GET['start'])){$start = $_GET['start'];}else{$start = 0;}
//GLOBAL $start;
//query DB
$query_total = "SELECT file_id
FROM files
WHERE file_section_id =" . $sec_id ;
$query = "SELECT file_id, file_meeting_date, file_meeting_time,
file_title, file_modified, file_section_id, sec_name, sec_id,
sec_disp_archive
FROM files f, section s
WHERE f.file_section_id =" . $sec_id . " AND f.file_section_id = s.sec_id
ORDER BY file_modified DESC LIMIT " . $start . "," . $num_item;
$result = mysqli_query( $link, $query ) or die(mysqli_error($link));
$result_total = mysqli_query( $link, $query_total ) or
die(mysqli_error($link));
$num_rows = mysqli_num_rows($result_total);
//print $query;
//create hyperlinks and display table
//display current file
/* print "START: " . $start . "NUMBER: " .$num_item . " ROWS: " .
$num_rows;*/
/*$obj = mysqli_fetch_object($result);*/
if ($num_rows > 1){ //Display current and archive files
//only display current table if start is not set (not on page 1)
$obj = mysqli_fetch_object($result);//Call DB
$content = "<div id ='MainContent'><p><b>" . $obj->sec_name .
"</b></p><table width='100%' border='1'>";
if (!isset($_GET['start'])||$_GET['start']==0){
//for 1st item display file info
$content.= "<tr><td colspan='3' align='center'>Current</td></tr>";
$content.= "<tr bgcolor='#CCCCCC'><td width='33%'>Meeting Date</td><td
width='33%'>Meeting Time</td><td width='34%'>File</td></tr>";
$content .= "<tr><td>" . date("F jS,
Y",strtotime($obj->file_meeting_date)) . "</td><td>" . date("g:i
A",strtotime($obj->file_meeting_time)) . "</td><td><a href='" . $updir .
$obj->file_title . "'>" . "View Current File" . "</td><tr>";
$content .="</table>";
print "START: " . $start . "NUMBER: " .$num_item . " ROWS: " . $num_rows;
//DEBUG
}
//Create seperate table for archive items
$content.= "<table width='100%' border='1'>";
$content.="<tr><td colspan='3' align='center'>Archive</td></tr>";
$content.="<tr bgcolor='#CCCCCC'><td width='33%'>Meeting Date</td><td
width='33%'>Meeting Time</td><td width='34%'>File</td></tr>";
//List archive items
while($obj = mysqli_fetch_object($result)){
$content .= "<tr><td>" . date("F jS,
Y",strtotime($obj->file_meeting_date)) . "</td><td>" . date("g:i
A",strtotime($obj->file_meeting_time)) . "</td><td><a href='" . $updir .
$obj->file_title . "'>" . "View Archived File" . "</td><tr>";
}
$content.= "</table>";
print "*START: " . $start . " *NUMBER: " .$num_item . " *ROWS: " .
$num_rows;
//create navigation
//If there are more files to display, display a next link (number of files
is greater than start # + # per page)
if ($num_rows > ($start+$num_item)) {
$content.="<a href = '" . $_SERVER['PHP_SELF'] . "?start=" . ($start +
$num_item) . "&sec_id=" . $sec_id . "&num_item=" . $num_item . "'>
Next</a>";
}
//If there are previous files to display, show previous link (start# is
greater than 0)
if ($start > 0) {
$content.="<a href = '" . $_SERVER['PHP_SELF'] . "?start=" .
($start - $num_item) . "&sec_id=" . $sec_id . "&num_item=" . $num_item .
"'>Back</a> |";
}
} else {//Display only current file
//Call DB
$obj = mysqli_fetch_object($result);
$content = "<div id ='MainContent'><p><b>" . $obj->sec_name .
"</b></p><table width='100%' border='1'>";
//display file info
$content.= "<tr><td colspan='3' align='center'>Current</td></tr>";
$content.= "<tr bgcolor='#CCCCCC'><td width='33%'>Meeting Date</td><td
width='33%'>Meeting Time</td><td width='34%'>File</td></tr>";
$content .= "<tr><td>" . date("F jS,
Y",strtotime($obj->file_meeting_date)) . "</td><td>" . date("g:i
A",strtotime($obj->file_meeting_time)) . "</td><td><a href='" . $updir .
$obj->file_title . "'>" . "View Current File" . "</td><tr>";
$content .="</table>";
print "START: " . $start . "NUMBER: " .$num_item . " ROWS: " . $num_rows;
//DEBUG
}
$content.= "</form>";
print $content;
print "START: " . $start . "NUMBER: " .$num_item . " ROWS: " . $num_rows;
mysqli_close($link);

Oct 25 '05 #1
1 1940
I was able to get this to work by creating a seperate SQL query to get the
section name and then saving that as a variable and calling the variable
later in the code. Now I have a new question: Is there a better way to do
this? I currently use 3 different queries to create the page and wonder if
this is OK or if this would be considered bad coding.

-Mark
Oct 25 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Marcel | last post by:
Hello, I'm working on a search application for my website. The website contains a lot of pictures, and a search should return clickable thumbnails. No problems there. My problem started when I...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
23
by: casper christensen | last post by:
Hi I run a directory, where programs are listed based on the number of clicks they have recieved. The program with most clicks are placed on top and so on. Now I would like people to be apple to...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
1
by: vikjohn | last post by:
I have a new perl script sent to me which is a revision of the one I am currently running. The permissions are the same on each, the paths are correct but I am getting the infamous : The specified...
16
by: gnawz | last post by:
I have a pagination function I am using in a file called functions.php as below<? //Pagination functions function getPagingQuery($sql, $itemPerPage = 10) { if (isset($_GET) && (int)$_GET > 0) ...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.