|
Posted by Mark ??;-\) on 10/22/05 05:45
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);
[Back to original message]
|