FRONTLIMIT){ $sqlPaged = "SELECT * FROM ".$_GET['sort_by']." WHERE deleted=0 ORDER BY last_name ASC LIMIT $start,FRONTLIMIT"; $qryPaged = mysql_query($sqlPaged); }else{ $qryPaged = $qryAll; } }else{ $sqlAll = "SELECT * FROM ".$_GET['sort_by']." t WHERE deleted=0 ORDER BY topic ASC"; $qryAll = mysql_query($sqlAll); if(mysql_num_rows($qryAll) > FRONTLIMIT){ $sqlPaged = "SELECT * FROM ".$_GET['sort_by']." t WHERE deleted=0 ORDER BY topic ASC LIMIT $start,FRONTLIMIT"; $qryPaged = mysql_query($sqlPaged); }else{ $qryPaged = $qryAll; } } $_SESSION['sort_by'] = $_GET['sort_by']; $sort_by = $_GET['sort_by']; }else{ $sort_by = "authors"; //we're going to sort by author by default $sqlAll = "SELECT * FROM authors a ORDER BY last_name ASC"; $qryAll = mysql_query($sqlAll); if(mysql_num_rows($qryAll) > FRONTLIMIT){ $sqlPaged = "SELECT * FROM authors ORDER BY last_name ASC LIMIT $start,FRONTLIMIT"; $qryPaged = mysql_query($sqlPaged); }else{ $qryPaged = $qryAll; } } print_header(); if(mysql_num_rows($qryPaged)>0){ $num = 0; while($row = mysql_fetch_assoc($qryPaged)){ if($sort_by=='topics'){ $name_arr= preg_split('//', $row['topic'], -1, PREG_SPLIT_NO_EMPTY); }else{ $name_arr= preg_split('//', $row['last_name'], -1, PREG_SPLIT_NO_EMPTY); } if($num == 0){ $the_letter = $name_arr[0]; $num++; $show_letter = true; }elseif($name_arr[0]!=$the_letter){ $the_letter = $name_arr[0]; $show_letter = true; }else{ $show_letter = false; } if($show_letter){ echo ""; echo "

".$name_arr[0]."

"; echo "
"; } if($sort_by=='topics'){ echo "".$row['topic']."
"; }else{ echo "".$row['last_name'].", ".$row['first_name']."
"; } } }else{ echo "Nothing available in the database"; } print_footer(); ?>