Code: Select all
<?php
if (isset($_POST['searching']) || isset($_GET['page'])) { // Handle the form.
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 3;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
require_once ('../includes/mysql.inc'); // Connect to the database.
if ($GENRE=='ALTERNATIVEROCK') { $GENRE='Alternative Rock'; }
if($GENRE=='0' && $SUB=='0' && $LANG1=='0') { //nothing selected
$query = "SELECT * from song AS s, user AS u WHERE s.status!='Pending' AND u.useracc=s.useracc ORDER BY s.status, s.songname, u.username, s.description ASC LIMIT $from, $max_results";
$result = mysql_query ($query);
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM song AS s, user AS u WHERE s.status!='Pending' AND u.useracc=s.useracc"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
}
if($GENRE=='0') { $displayGenre='---'; }
else { $displayGenre=$GENRE; }
if($SUB=='0') { $displaySub='---'; }
else { $displaySub=$SUB; }
if($LANG1=='0') { $displayLang='---'; }
else { $displayLang=$LANG1; }
echo "Viewing Songs with Genre: <b>$displayGenre</b>, Sub-Genre: <b>$displaySub</b> and Language: <b>$displayLang</b>";
$nosong = 1;
if ($result) {
echo "<table width="800" border="0" cellspacing="0" cellpadding="0">";
echo "<tr>
<td><b>Status:</b></td>
<td><b>Song Name:</b></td>
<td><b>Author Name:</b></td>
<td><b>Description:</b></td>
</tr>";
$flag=1;
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>{$row['status']}</td>
<td>{$row['songname']}</td>
<td>{$row['username']}</td>
<td>{$row['description']}</td>";
echo "</tr>";
$nosong= 0;
$flag=0;
echo "<tr><td colspan="4">-------------------------------------------------------------------------------------------------------------------------</td></tr>";
}// end of while $rowz
if($nosong==1) {
echo "<tr><td colspan="4"><div align="center">No songs found</div></td></tr>";
}
} //end of if result true
else {
echo "There is an error on the page. Please submit search again";
}
// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href="".$_SERVER['PHP_SELF']."?page=$prev"><<Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href="".$_SERVER['PHP_SELF']."?page=$i">$i</a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href="".$_SERVER['PHP_SELF']."?page=$next">Next>></a>";
}
echo "</center>";
?>Hey i got this problem that my rest of the pages does not display anything... can anyone help me?? once i click on page 2 it will display no songs found....