I have been trying to write some code to sort emails that I add to the database for a newsletter I send out each month. Right now I can make it output all of my entries, but I cant figure out the linkage to make it sort properly. I have rewrote it several ways and none work. I now turn it over to the gurus to find my answer. The newsletter function is what is output to the page primarily. Then if a sort link is clicked, it will goto the sort_email function using the letter I send it. Btw, I have tried coding it with the standard A-Z links, and also a pull-down menu. I dont necessarily need to use a function to get this sort working, Im just unsure how to write it properly. Lastly, If I un-comment the $A-$Z variables it runs the sort_email function for the $A variable and it displays properly.
To recap, I need help with the links code and/or the rest of it. Thanx guys.
Here is the code I currently have:
function sort_email($letter) {
global $user_prefix, $db, $sitename;
include("header.php");
GraphicAdmin();
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$query = "SELECT nlid, email FROM " . $user_prefix . "_newsletter WHERE email LIKE '$letter%' ORDER BY email ASC";
$result = mysql_query($query);
$query_data = @mysql_fetch_row($result);
$numrows = $query_data[0];
$rows_per_page = 30;
$lastpage = ceil($numrows/$rows_per_page);
OpenTable();
echo "<center><b>Off-Site Email Administration</b><br><br>"
."<a href=\"admin.php?op=newsletter\">[Back to Newsletter Main]</a><br></center>"
."<hr><br><center><b><u>Off-Site Email Index</b></u><br><br>";
echo "<form method=\"POST\" action=\"$PHP_SELF\">"
."<b>Sort by Letter</b> "
."<select name=\"letter\"><option>Choose One</option>"
."<option value=\"A\">A</option>"
."<option value=\"B\">B</option>"
."<option value=\"C\">C</option>"
."<option value=\"D\">D</option>"
."<option value=\"E\">E</option>"
."<option value=\"F\">F</option>"
."<option value=\"G\">G</option>"
."<option value=\"H\">H</option>"
."<option value=\"I\">I</option>"
."<option value=\"J\">J</option>"
."<option value=\"K\">K</option>"
."<option value=\"L\">L</option>"
."<option value=\"M\">M</option>"
."<option value=\"N\">N</option>"
."<option value=\"O\">O</option>"
."<option value=\"P\">P</option>"
."<option value=\"Q\">Q</option>"
."<option value=\"R\">R</option>"
."<option value=\"S\">S</option>"
."<option value=\"T\">T</option>"
."<option value=\"U\">U</option>"
."<option value=\"V\">V</option>"
."<option value=\"W\">W</option>"
."<option value=\"X\">X</option>"
."<option value=\"Y\">Y</option>"
."<option value=\"Z\">Z</option>"
."</select> "
."<input type=\"hidden\" name=\"op\" value=sort_email>"
."<input type=\"submit\" name=\"submit\" submit value=\"GO!\"></form>";
echo "</center><br>";
echo "<table width=\"90%\" cellspacing=\"1\" cellpadding=\"6\" border=\"0\" align=\"center\">"
."<tr>"
."<td width=\"10%\" align=\"center\"><b>No.</b></td>"
."<td width=\"60%\" align=\"left\"><b>Email Address</b></td>"
."<td width=\"30%\" align=\"center\"><b>Functions</b></td>"
."</tr></table>";
$pageno = (int)$pageno;
if ($pageno < 1) {
$pageno = 1;
} elseif ($pageno > $lastpage) {
$pageno = $lastpage;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query1 = "SELECT nlid, email FROM " . $user_prefix . "_newsletter WHERE email LIKE '$letter%' ORDER BY email ASC $limit";
$emailno = 1;
$query_result1 = mysql_query($query1);
while ($row = @mysql_fetch_array($query_result1)) {
echo "<table width=\"90%\" cellspacing=\"1\" cellpadding=\"6\" border=\"0\" align=\"center\">"
."<tr bgcolor=\"#e6e6e6\">"
."<td width=\"10%\" align=\"center\">$emailno.</td>"
."<td width=\"60%\" align=\"left\">$row[email]</td>"
."<td width=\"30%\" align=\"center\">N/A"
."</td>"
."</tr></table>";
$emailno++;
}
if ($pageno == 1) {
echo "<table width=\"90%\" border=\"0\" align=\"center\"><tr><td align=\"center\">";
echo " FIRST PREV ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?op=sort_email&pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?op=sort_email&pageno=$prevpage'>PREV</a> ";
}
echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage) {
echo " NEXT LAST ";
} else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?op=sort_email&pageno=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?op=sort_email&pageno=$lastpage'>LAST</a> ";
}
echo "</td></tr>";
echo "</table>";
CloseTable();
include("footer.php");
}