All pastes #729034 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-10-07 16:25 UTC
rendered paste body
<?php 
//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum))):
	$pagenum = 1;
endif;

$avg = mysql_query("
	SELECT AVG(OverallRating) AS AverageRating
	FROM Rating_Test
	WHERE AirportCode = '" . $sub3 . "'
");
while ($row = mysql_fetch_array($avg)):
	$avgRating = $row['AverageRating'];
endwhile;

//Here we count the number of results
//Edit $data to be your query
$data = mysql_query("
	SELECT Name
	FROM Rating_Test
	WHERE AirportCode = '" . $sub3 . "'
	ORDER BY SubmissionDate
") or die(mysql_error());
$rows = mysql_num_rows($data);
?>

<h2>Security Profile for <?=$sub3;?></h2>
 - Overall Safety Rating: <?=$avgRating;?><br />
 - Rated by <?=$rows;?> fliers</br />

<?php
//This is the number of results displayed per page
$page_rows = 10;

//This tells us the page number of our last page
$last = ceil($rows/$page_rows);

//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1):
	$pagenum = 1;
elseif ($pagenum > $last):
	$pagenum = $last;
endif;
?>

<!--h2>Security Profile for <?=$sub3;?></h2>
 - Overall Safety Rating: <?=$avgRating;?><br />
 - Rated by <?=$rows;?> fliers</br /-->

<?php
$data_p = mysql_query("
	SELECT Name, OverallRating, Comments
	FROM Rating_Test
	WHERE AirportCode = '" . $sub3 . "'
	ORDER BY SubmissionDate
	LIMIT " . $rows . " OFFSET 10
") or die(mysql_error());

#This is where you display your query results

while($info = mysql_fetch_array($data_p)): ?>

    <h3>Review by <?=$info['Name'];?> - rated <?=$sub3;?> +<?=$info['OverallRating'];?></h3>
    <?=$info['Comments'];?>
    <hr />

<?php endwhile;?>

<?php
// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
if ($pagenum == 1):
else: ?>
	<a href="<?={$_SERVER['PHP_SELF']};?>?pagenum=1">&laquo;First 10</a>&nbsp;
	<?php $previous = $pagenum-1;?>
	<a href='<?={$_SERVER['PHP_SELF']}$?>?pagenum=<?=$previous;?>'><?=$previous;?></a>&nbsp;
<?php endif;?>

<?php
//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last):
else: 
	$next = $pagenum+1;?>
	<a href='<?={$_SERVER['PHP_SELF']};?>?pagenum=$next'><?=$next;?></a>&nbsp;
	<a href='<?={$_SERVER['PHP_SELF']};?>?pagenum=$last'>Last 10 &raquo;</a>
<?php endif;?>
<!--a href='#'>&laquo;Prev 10</a>&nbsp;
<a href='#'>1</a>&nbsp;
<a href='#'>2</a>&nbsp;
<a href='#'>3</a>&nbsp;
<a href='#'>Next 10 &raquo;</a-->