Click to See Complete Forum and Search --> : show next 5


kproc
01-15-2007, 08:33 PM
The below code is supposed to get the next five names. For some reason its to doing anything when I click next. any help is excellent


<?
// groups and count the number of family names found in database
if(empty($_GET['start'])){
$start=0;
}else{
$start=$_GET['start'];
}
$end=$start+5;
$sql= mysql_query("SELECT last_name, count( * ) AS count FROM `users` GROUP BY `last_name` LIMIT $start,$end");
?>
<table class="columntable">
<tr><td class="tableheader" colspan="2">Registerd Family Names</td></tr>
<tr><td class="rowLeft">Last Name</td>
<td class="rowRight">Family Count</td></tr>
<?php
while($r=mysql_fetch_assoc($sql)) {
$query = mysql_query("SELECT last_name FROM `users` WHERE `last_name` = '$r[last_name]'") or die(mysql_error());
$last_name = $r['last_name'];
$count = mysql_num_rows($query);
?>
<tr>
<td class="rowLeft"><? echo $last_name; ?>
</td>
<td class="rowRight"><?php echo $count; ?>
</td>
</tr>
<?php }

$back = $_SERVER['PHP_SELF']."?start=$end";
?>
<tr style="background-color:#ECFEE9;"><td><input type="button" value="Next" onClick="window.location=<?php echo $back; ?>" /></td>
<td><input style="float:right;" type=button value="Prev" onClick="history.go(-1)"></td></tr>
</table>
<?php

NightShift58
01-15-2007, 10:09 PM
<?
$start = empty($_GET['start']) ? 0 : $_GET['start'];
$end = $start + 5;

// groups and count the number of last names found in database
$sql = "SELECT last_name, count(*) AS count FROM `users` GROUP BY `last_name` ORDER BY `last_name` LIMIT $start,$end";
$qry = mysql_query($sql) or die("SQL Error: $sql<br>" . mysql_error());

print "<table class='columntable'>";
print "<tr><td class='tableheader' colspan='2'>Registerd Family Names</td></tr>";
print "<tr><td class='rowLeft'>Last Name</td>";
print "<td class='rowRight'>Family Count</td></tr>";

while ($r = mysql_fetch_assoc($sql)) {
print "<tr>";
print "<td class='rowLeft'>{$r['last_name']}</td>";
print "<td class='rowRight'>{$r['count']}</td>";
print "</tr>";
}

$back = $_SERVER['PHP_SELF'] . "?start=$end";
print "<tr style='background-color:#ECFEE9;'>";
print "<td><input type='button' value='Next' onClick=\"window.location='$back';\"></td>";
print "<td><input style='float:right;' type=button value='Prev' onClick='history.go(-1)'></td>";
print "</tr>";
print "</table>";
?>

kproc
01-16-2007, 06:52 AM
Hi do you mind me asking why you used print and not echo. my is the better the n the way I had it (other then it works :) )

why do you write out the qtring to query then query it.

I'm trying to learn the rops as I go along thank you

NightShift58
01-16-2007, 07:26 AM
Old habits...