473,770 Members | 5,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_da te, file_meeting_ti me,
file_title, file_modified, file_section_id , sec_name, sec_id,
sec_disp_archiv e
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_erro r($link));
$result_total = mysqli_query( $link, $query_total ) or
die(mysqli_erro r($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_ob ject($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_ob ject($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='#CCCCC C'><td width='33%'>Mee ting Date</td><td
width='33%'>Mee ting Time</td><td width='34%'>Fil e</td></tr>";
$content .= "<tr><td>" . date("F jS,
Y",strtotime($o bj->file_meeting_d ate)) . "</td><td>" . date("g:i
A",strtotime($o bj->file_meeting_t ime)) . "</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='#CCCCC C'><td width='33%'>Mee ting Date</td><td
width='33%'>Mee ting Time</td><td width='34%'>Fil e</td></tr>";
//List archive items
while($obj = mysqli_fetch_ob ject($result)){
$content .= "<tr><td>" . date("F jS,
Y",strtotime($o bj->file_meeting_d ate)) . "</td><td>" . date("g:i
A",strtotime($o bj->file_meeting_t ime)) . "</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_it em)) {
$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_ob ject($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='#CCCCC C'><td width='33%'>Mee ting Date</td><td
width='33%'>Mee ting Time</td><td width='34%'>Fil e</td></tr>";
$content .= "<tr><td>" . date("F jS,
Y",strtotime($o bj->file_meeting_d ate)) . "</td><td>" . date("g:i
A",strtotime($o bj->file_meeting_t ime)) . "</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($l ink);

Oct 25 '05 #1
1 1964
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
3056
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 wanted to build in NEXT and PREVIOUS buttons, so that you only get 5 or 10 or 20 (I haven't made up my mind yet) thumbnails at a time. I use a SQL LIMIT statement to achieve that. After displaying the first 5 pictures I would like to see the next 5,...
8
5481
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 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
9
4354
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 predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user for any changes of ratings on that day. The resulting data table grows by approx 600 records per...
1
3721
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 attach this script files and inq files. I cant understand this error. Please suggest me. You can talk with my yahoo id b_sahoo1@yahoo.com. Now i am online. Plz....Plz..Plz...
23
2803
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 place a link on there site so people can vote for their program, "ad a click". eg someone clicks the link on some page and it counts +1 click on my page. if some one clicks the link below it will count a click on my page.
0
5576
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 ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
9
3944
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 - I have read every post out there and spent hours trying to figure out the problem with no success whatsoever - I have constrained the problem to one form however, and I think it's hiding somewhere in my code associated with this form, which is...
1
2939
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 CGI application misbehaved by not returning a complete set of HTTP headers. The scripts are very long but here are the opening statements: The One that works .... #!C:\Perl\bin\perl.exe # openresolver.cgi # # OpenResolver - a CGI script for...
16
2781
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) { $page = (int)$_GET; } else { $page = 1; } // start fetching from this row number $offset = ($page - 1) * $itemPerPage; return $sql . " LIMIT $offset, $itemPerPage"; } /* Get the links to navigate between...
0
10232
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10008
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8891
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7420
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2822
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.