auto incrementing rows from query..
| From: | Chad Day | Date: | Tue, 05 Dec 2000 21:07:19 +0000 |
| Subject: | auto incrementing rows from query.. | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-5030@lists.php.net to get a copy of this message | ||
I'm trying to determine the percentile value of where a row lies in a
query.. hard to explain, but I'll try.
I do a select all of my table, sorting it by SCORE. I want to find the
position of a certain row in that select all, get that row #, and then I can
calculate the percentile fine by dividing that position into the total # of
rows, then multiplying by 100.
my code is like:
$querysetup = "SELECT SCORE, PID from pictures where VOTES > 100 order by
SCORE DESC";
$query = mysql_query($querysetup);
$num = ??? position of that row, don't know how to get this.
$numrows = mysql_num_rows($query);
if (!mysql_data_seek($query, $num)) {
printf ("Cannot seek to row %d\n", $num);
exit();
} else {
if ($row = mysql_fetch_array($query)) {
echo "<br>";
echo $row[SCORE];
echo "<br>";
echo $row[PID];
}
}
I thought doing a query like:
SELECT SCORE, PID, RANK as (RANK + 1) from pictures where VOTES > 100 order
by SCORE DESC;
would work, but it doesn't.. using an auto_increment field in the table
won't work since it will be all jumbled by the ORDER BY .. so how do I most
efficicently get that row position?
Thanks,
Chad Day
Beach Associates
When I speak german... I think german in my head... but like...Do skript
kiddies see a w40l3 8uncha 1's and 0's and 3's and 4's and 7's in their
h34d'5 w43n t43y R +a1k1n6 ? -- SirStanley