function sortalpha($letter,$sortby,$page){
include("header.php");
$pagesize = 20;
if (!isset($letter)) { $letter = "A"; }
if (!isset($sortby)) { $sortby = "sname"; }
if (!isset($page)) { $page = 1; }
/ All of the code from here to around line 125 will be optimized a little later /
/ This is the header section that displays the last registered and who's logged in and whatnot /
$result = sql_query("select sname from divebase order by id DESC limit 0,1", $dbi);
list($lastuser) = sql_fetch_row($result, $dbi);
echo "\n\n<!-- SITE LIST -->\n\n";
OpenTable();
echo "<center><b>".WELCOMETO." $sitename ".DIVEALPHALIST."</b><br><br>\n";
echo ""._GREETINGS." <A HREF=\"modules.php?name=Your_Account&op=userinfo&uname=$lastuser\">$lastuser</a>\n</center>\n<br>\n";
$numrows = sql_num_rows(sql_query("select id from divebase", $dbi), $dbi);
echo "<center>"._WEHAVE." <b>$numrows</b> "._REGSOFAR."</center>\n<br>\n<br>\n";
alpha();
SortLinks($letter);
/ end of top memberlist section thingie /
/ This starts the beef.../
$min = $pagesize * ($page - 1); // This is where we start our record set from
$max = $pagesize; // This is how many rows to select
/* All my SQL stuff. DO NOT ALTER ANYTHING UNLESS YOU KNOW WHAT YOU ARE DOING */
/ This is a totaly crap code, any help to re-code this functions will be very appreciated /
/ Need to be database independent /
$count = "SELECT COUNT(id) AS total FROM divebase"; // Count all the users in the db..
$select = "select id, aka, sname, email, cat from divebase "; //select our data
$where = "where sname != '' ";
if ( ( $letter != "Other" ) AND ( $letter != "All" ) ) { // are we listing all or "other" ?
$where .= "AND sname like '".$letter."%' "; // I guess we are not..
} else if ( ( $letter == "Other" ) AND ( $letter != "All" ) ) { // But other is numbers ?
$where .= "AND sname REGEXP \"^\[1-9]\" "; // REGEX :D, although i think its MySQL only
// Will have to change this later.
// if you know a better way to match only the first char
// to be a number in uname, please change it and email
// [email]myphportal-developers@lists.sourceforge.net[/email] the correction
// or goto [url]http://sourceforge.net/projects/myphportal[/url] and post
// your correction there. Thanks, Bjorn.
} else { // or we are unknown or all..
$where .= ""; // this is to get rid of anoying "undefinied variable" message
}
$sort = "order by $sortby"; //sorty by .....
$limit = " ASC LIMIT ".$min.", ".$max; // we only want rows $min to $max
/* due to how this works, i need the total number of users per
letter group, then we can hack of the ones we want to view */
$count_result = sql_query($count.$where, $dbi);
$num_rows_per_order = mysql_result($count_result,0,0);
/* This is where we get our limit'd result set. */
$result = sql_query($select.$where.$sort.$limit, $dbi) or die(); // Now lets do it !!
/ Crap code ends here /
echo "<br>";
if ( $letter != "front" ) {
echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\"><tr>\n";
echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\"><font color=\"$textcolor2\"><b>"._SITENAME."</b></font></td>\n";
echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\"><font color=\"$textcolor2\"><b>"._AKA."</b></font></td>\n";
echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\"><font color=\"$textcolor2\"><b>"._EMAIL."</b></font></td>\n";
echo "<td BGCOLOR=\"$bgcolor4\" align=\"center\"><font color=\"$textcolor2\"><b>"._CAT."</b></font></td>\n";
$cols = 4;
echo "</tr>";
$a = 0;
$dcolor_A = "$bgcolor2";
$dcolor_B = "$bgcolor1";
$num_users = sql_num_rows($result, $dbi); //number of users per sorted and limit query
if ( $num_rows_per_order > 0 ) {
while($user = sql_fetch_array($result, $dbi)) {
$dcolor = ($a == 0 ? $dcolor_A : $dcolor_B);
echo "<tr><td bgcolor=\"$dcolor\"><A HREF=\"modules.php?op=modload&name=divebase&file=index&go=view&id=$id[sname]\"><font color=\"$textcolor1\">$id[sname]</font></a> </td>\n";
echo "<td bgcolor=\"$dcolor\"><font color=\"$textcolor1\">$sname[sname]</font> </td>\n";
echo "<td bgcolor=\"$dcolor\"><font color=\"$textcolor1\">$email[email]</font> </td>\n";
if ($user[url] == "") {
$url2 = " ";
} else {
// $urlno = eregi_replace("http://modules.php?op=modload&name=divebase&file=index&go=view&id=$id",);
// $url2 = "<a href=\"http://$urlno\" target=\"new\">"._HOMEPAGE."</a>";
}
echo "<td bgcolor=\"$dcolor\" align=\"center\">$cat</td>\n";
echo "</tr>";
$a = ($dcolor == $dcolor_A ? 1 : 0);
// start of next/prev/row links.
echo "\n<tr><td colspan='$cols' align='right'>\n";
echo "<br><br>";
OpenTable();
echo "\t<table width='100%' cellspacing='0' cellpadding='0' border=0><tr>";
if ( $num_rows_per_order > $pagesize ) {
$total_pages = ceil($num_rows_per_order / $pagesize); // How many pages are we dealing with here ??
$prev_page = $page - 1;
if ( $prev_page > 0 ) {
echo "<td align='left' width='15%'><a href='modules.php?name=$module_name&letter=$letter&sortby=$sortby&page=$prev_page'>";
echo "<img src=\"images/left.gif\" border=\"0\" alt=\""._PREVIOUS." ($prev_page)\" title=\""._PREVIOUS." ($prev_page)\"></a></td>";
} else {
echo "<td width='15%'> </td>\n";
}
echo "<td align='center' width='70%'>";
echo "<font class=tiny>$num_rows_per_order "._SITEFOUND." <b>$letter</b> ($total_pages "._PAGES.", $num_users "._SITESHOWN.")</font>";
echo "</td>";
$next_page = $page + 1;
if ( $next_page <= $total_pages ) {
echo "<td align='right' width='15%'><a href='modules.php?name=$module_name&letter=$letter&sortby=$sortby&page=$next_page'>";
echo "<img src=\"images/right.gif\" border=\"0\" alt=\"Next Page ($next_page)\" title=\"Next Page ($next_page)\"></a></td>";
} else {
echo "<td width='15%'> </td></tr>\n";
}
/* Added a numbered page list, only shows up to 50 pages. */
echo "<tr><td colspan=\"3\" align=\"center\">";
echo " <font class=tiny>[ </font>";
for($n=1; $n < $total_pages; $n++) {
if ($n == $page) {
echo "<font class=tiny><b>$n</b></font></a>";
} else {
echo "<a href='modules.php?name=$module_name&letter=$letter&sortby=$sortby&page=$n'>";
echo "<font class=tiny>$n</font></a>";
}
if($n >= 50) { // if more than 50 pages are required, break it at 50.
$break = true;
break;
} else { // guess not.
echo "<font class=tiny> | </font>";
}
}
if(!isset($break)) { // are we sopposed to break ?
if ($n == $page) {
echo "<font class=tiny><b>$n</b></font></a>";
} else {
echo "<a href='modules.php?name=$module_name&letter=$letter&sortby=$sortby&page=$total_pages'>";
echo "<font class=tiny>$n</font></a>";
}
}
echo " <font class=tiny>]</font> ";
echo "</td></tr>";
/* This is where it ends */
}else{ // or we dont have any users..
echo "<td align='center'>";
echo "<font class=tiny>$num_rows_per_order "._SITEFOUND." $letter</font>";
echo "</td></tr>";
}
echo "</table>\n";
CloseTable();
echo "</td></tr>\n";
// end of next/prev/row links
echo "<tr><td bgcolor=\"$dcolor_A\" colspan=\"$cols\" align=\"center\"><br>\n";
echo "<b><font color=\"$textcolor1\">"._NOSITE." $letter</font></b>\n";
echo "<br></td></tr>\n";
echo "\n</table><br>\n";
}
CloseTable();
include("footer.php");
}