Page 1 of 1

Deleted MySQL Rows, Count Still Picks Them Up

Posted: Sun Sep 10, 2006 4:29 am
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.

Posted: Sun Sep 10, 2006 5:37 am
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");