On 22/02/11 05:40, Gary wrote:
Can someone tell me why this is not working? I do not get an error message,
the results are called and echo'd to screen, the count does not work, I get
a 0 for a result...
$result = mysql_query("SELECT * FROM `counties` WHERE name = 'checked'") or
die(mysql_error());
if ( isset($_POST['submit']) ) {
for($i=1; $i<=$_POST['counties']; $i++) {
if ( isset($_POST["county$i"] ) ) {
echo "You have chosen ". $_POST["county$i"]."<br/>";
}
}
}
$county_total=mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{$i++;
echo $row['name'];
}
$county_total=mysql_num_rows($result);
echo "$county_total";
echo 'You Have ' . "$county_total" . ' Counties ';
?>
The first thing I see is that you do
$county_total=mysql_num_rows($result)
twice. Now I'm not to sure, but it is possible that looping over
mysql_fetch_array($result) moves an array pointer so the count is not valid
after the operation... that's a long shot.
But since you are looping over the database records anyway, why not just count
them as you go? Isn't $i the number of counties after all the looping?
--
Peter Ford, Developer phone: 01580 893333 fax: 01580 893399
Justcroft International Ltd. www.justcroft.com
Justcroft House, High Street, Staplehurst, Kent TN12 0AH United Kingdom
Registered in England and Wales: 2297906
Registered office: Stag Gates House, 63/64 The Avenue, Southampton SO17 1XS
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php