Deleted MySQL Rows, Count Still Picks Them Up

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
richo
Forum Commoner
Posts: 58
Joined: Sun Aug 06, 2006 11:56 am

Deleted MySQL Rows, Count Still Picks Them Up

Post by richo »

I count the number of rows and then loop through to the total number. But after deleting a couple of rows, it still counts that number even though they don't exist anymore.

Relevant code below:

count:

Code: Select all

$rowTotal = mysql_query("SELECT COUNT(*) FROM slides");
for loop:

Code: Select all

for ($i=1; $i<=$rowTotal; $i++){
		$row = mysql_fetch_array($result);
		echo "<li><a href=\"?slide=" . $row["pkey"] . "\">" . $i . "</a></li>";
	}
Also when echoing out the count, it displays as 5, instead of 3. When doing the the count in MySQL Query Browser, it displays as the correct 3.
richo
Forum Commoner
Posts: 58
Joined: Sun Aug 06, 2006 11:56 am

Post by richo »

If it helps anyone answer my question, it was somehow fixed when i did this instead:

Code: Select all

$result = mysql_query("SELECT * FROM slides");
$rowTotal = mysql_num_rows($result);
Is it possible that there was some kind of clashing before with the:

Code: Select all

$result = mysql_query("SELECT * FROM slides");
$rowTotal = mysql_query("SELECT COUNT(*) FROM slides");
Post Reply