Recently a friend of mine set up a script where a page displays a list of database entries… the page is here: http://www.gatorhelpers.com/eventlists.php
I need to have several links that allow the visitor to sort the list, but I dont know how to do this.
Here is the code for the entire page:
<?php
include_once("includes/top_PHPConnection.php");
?>
<?php
//Set the page size
if(isset($_GET["txtdisplay"]))
{
$PageSize=$_GET["txtdisplay"];
}
else
{
$PageSize = 10;
}
$StartRow = 0;
//Set the page no
if(empty($_GET['PageNo'])){
if($StartRow == 0){
$PageNo = $StartRow + 1;
}
}else{
$PageNo = $_GET['PageNo'];
$StartRow = ($PageNo - 1) * $PageSize;
}
//Set the counter start
if($PageNo % $PageSize == 0){
$CounterStart = $PageNo - ($PageSize - 1);
}else{
$CounterStart = $PageNo - ($PageNo % $PageSize) + 1;
}
//Counter End
$CounterEnd = $CounterStart + ($PageSize - 1);
$TRecord1 = "select * from tbl_events where event_status='1'";
$TRecord = $db->execute_query($TRecord1);
$result1 = "select * from tbl_events where event_status='1' order by event_startdate asc LIMIT $StartRow,$PageSize";
$result = $db->execute_query($result1);
//Total of record
$RecordCount = mysql_num_rows($TRecord);
//Set Maximum Page
$MaxPage = $RecordCount % $PageSize;
if($RecordCount % $PageSize == 0){
$MaxPage = $RecordCount / $PageSize;
}else{
$MaxPage = ceil($RecordCount / $PageSize);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GatorHelpers.com - Available Events</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<!--[if lt IE 7]>
<script defer type="text/javascript" src="js/pngfix.js"></script>
<![endif]-->
<script language="javascript" src="js/client_functions.js"/></script>
<script language="javascript">
<!--
function suredel1(){
if(confirm("Are you sure you want to delete this event?")){
return true;
}else{
return false;
}
}
-->
</script>
</head>
<body>
<table border="0" align="center" cellpadding="0" cellspacing="0" class="top_table">
<tr>
<td height="134" valign="top" class="top_table"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="heading">
<tr>
<td width="879" height="134" valign="top"><?php include_once("includes/top_HeaderNav.php");?></td>
<td width="129" valign="top"><!--DWLayoutEmptyCell--> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="304" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="128"> </td>
<td width="745" height="304" valign="bottom" align="center"><img src="images/headerimageswamp.jpg" alt="Welcome"/></td>
<td width="129"> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="421" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="129" rowspan="2" valign="top"><img src="images/spacer.gif" width="129" height="1" /></td>
<td width="750" height="62" valign="top"><?php include_once("includes/main_MenuNav.php");?></td>
<td width="129" rowspan="2" valign="top"><img src="images/spacer.gif" width="129" height="1" /></td>
</tr>
<tr>
<td height="359" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="286" valign="top" class="content_heading"><h1> Available Events and Volunteer Opportunities</h1>
<table width="100%" align="center" cellpadding="3" cellspacing="3" border="0">
<tr>
<td colspan="3">
<?php
//$resEventsListbyUser = $liab->EventsAllListS();
$bgcolor = "#DEDCDD";
if($RecordCount>0){
while($rsEventsListbyUser = mysql_fetch_array($result)){
if($bgcolor == "#DEDCDD"){
$bgcolor = "#D2D2D2";
}elseif($bgcolor == "#D2D2D2"){
$bgcolor = "#DEDCDD";
}
?>
<table onclick="javascript:window.location='eventdetails.php?detid=<?php echo $rsEventsListbyUser['event_id'];?>'" width="100%" cellpadding="5" cellspacing="5" border="0"><tr bgcolor="<?php echo $bgcolor;?>" height="27" onmouseover="this.className='NavMenuOver';" onmouseout="this.className='NavMenuOut';" class="NavMenuOut">
<td class="smalltext_lightGray"><div style="color:#00213A; font-size:14px;"><strong><?php echo $rsEventsListbyUser['event_name'];?></strong></div><br/><?php
$str = $rsEventsListbyUser['event_details'];
$text = "";
if(substr($str,0,4) == "<img"){
$i = 0;
while(1){
if($str[$i] == ">"){
$text = substr($str, $i+1, strlen($str));
break;
}
$i++;
}
}else{
$text =$str;
}
$text = str_replace("<br/>","",$text);
//limiting the no of words to display
$num = "20";
//word limit check
if($num)
{
$texts = explode(' ', $text);
$count = count($texts);
if ($count>$num)
{
$text = '';
for($i=0;$i<$num;$i++)
{
$text .= ' '. $texts[$i];
}
$text .= '...';
}
}
echo $text;
?><br/><br/><strong>Email:</strong> <?php echo $rsEventsListbyUser['event_email'];?>
<br/><strong>Contact No:</strong> <?php echo $rsEventsListbyUser['event_phoneno'];?>
<br/><strong>Organization Sponsoring Event:</strong> <?php echo $rsEventsListbyUser['event_sponorg'];?><div align="right"><?php /*?><a class="smalltext__Green" style="text-decoration:none;" href="index.php?page=memberhome&delid=<?php echo $rsEventsListbyUser['event_id'];?>" onclick="return(suredel1())">Delete</a><?php */?> </div></td>
</tr></table>
<?php
}
}else{
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="smalltext_lightGray" style="text-align:center;"><font color="#FF0000">No events found</font></td>
</tr>
</table>
<?php
}
?> </td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="smalltext_lightGray" style="text-align:right;">
<?php
//Print First & Previous Link is necessary
if($CounterStart != 1){
$PrevStart = $CounterStart - 1;
print "<a class='smalltext__Green' style='color:#0A0468; font-size:12px;' href=eventlists.php?PageNo=1><< Start</a> ";
print "<a class='smalltext__Green' style='color:#0A0468; font-size:12px;' href=eventlists.php?PageNo=$PrevStart>< Previous </a>";
}
$c = 0;
//Print Page No
for($c=$CounterStart;$c<=$CounterEnd;$c++){
if($c < $MaxPage){
if($c == $PageNo){
if($c % $PageSize == 0){
print "$c ";
}else{
print "$c, ";
}
}elseif($c % $PageSize == 0){
echo "<a class='smalltext__Green' style='color:#0A0468; font-size:12px;' href=eventlists.php?PageNo=$c>$c</a> ";
}else{
echo "<a class='smalltext__Green' style='color:#0A0468; font-size:12px;' href=eventlists.php?PageNo=$c>$c</a>, ";
}//END IF
}else{
if($PageNo == $MaxPage){
print "$c ";
break;
}else{
echo "<a class='smalltext__Green' style='color:#0A0468; font-size:12px;' href=eventlists.php?PageNo=$c>$c</a> ";
break;
}//END IF
}//END IF
}//NEXT
if($CounterEnd < $MaxPage){
$NextPage = $CounterEnd + 1;
echo "<a class='smalltext__Green' style='color:#0A0468; font-size:12px;' href=eventlists.php?PageNo=$NextPage>Next ></a> ";
}
//Print Last link if necessary
if($CounterEnd < $MaxPage){
$LastRec = $RecordCount % $PageSize;
if($LastRec == 0){
$LastStartRecord = $RecordCount - $PageSize;
}
else{
$LastStartRecord = $RecordCount - $LastRec;
}
echo "<a class='smalltext__Green' style='color:#0A0468; font-size:12px;' href=eventlists.php?PageNo=$MaxPage>End >></a>";
}
?> </td>
</tr>
</table></td>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td height="20" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="1008" height="20" valign="top"><img src="images/spacer.gif" width="1" height="1" /></td>
</tr>
</table></td>
</tr>
</table>
<div id="footer_div">
<?php include_once("includes/below_FooterNav.php");?>
</div>
</body>
</html>
Any help or direction would be great appreciated as I am really lost.
Thanks
Mike