Page 1 of 1

[Solved]Fetching 'total' returns 123 instead of 3

Posted: Fri Mar 26, 2004 5:39 pm
by Steveo31
I'm back again ;)

I have a DB set up with tables with 'name' and 'total'. 'total' is an auto_increment primary key. $location is a var of the name of the table to retrieve from. Here's my code to retrieve it:

Code: Select all

<?php

$getID = 'SELECT total FROM '.$location;
$getID_q = mysql_query($getID, $db);
while($row = mysql_fetch_assoc($getID_q)){
    echo $row['total'];
}
And this echoes all the values. Say I have entered 5 values in name... this would make the auto_increment value (total) be 5. No prob, but the above returns 12345 instead of 5. I think I need to use a WHERE in the original statement, but I'm not 100% sure on how.

I checked the mySQL manual but to no avail.

Posted: Fri Mar 26, 2004 5:51 pm
by andre_c
if you want to count the rows try this, (the auto_increment number is not the best way to keep track of how many rows you have)

Code: Select all

$total = mysql_num_rows($getID);
... or is it something different that you want?

Posted: Fri Mar 26, 2004 6:53 pm
by Steveo31
Perfect. Thank you!