Page 1 of 1

[SOLVED]pull value from specific row in a table

Posted: Sun Jun 12, 2011 5:47 pm
by mathruD
i'm having a problem with something that i feel should be fairly easy to do. say i had the following query that creates a list of names and ages of people in the state of texas (sorted alphabetically):

Code: Select all

<?php
mysql_select_db($database_somedatabase, $somedatabase);
$query_findPeople_rs = "SELECT firstname, age FROM people WHERE state = 'texas' ORDER BY firstname ASC";
$findPeople_rs = mysql_query($query_findPeople_rs, $thesilentcritic) or die(mysql_error());
$row_findPeople_rs = mysql_fetch_assoc($findPeople_rs);
$totalRows_findPeople_rs = mysql_num_rows($findPeople_rs);
?>
So let's say this pulls the following entries (assume all are from texas):
Adam 32
Bob 28
Dave 29
Jim 43
Jim 26
Mike 30
Phil 54
Steve 22
Steve 36

i check the number of rows by:

Code: Select all

<?php 
$counter = mysql_num_rows($findPeople); 
?>
This would set $counter to the number 9.
Now my question is, how would i store the first name of the person in the 9th row (Steve) as the variable $name

Code: Select all

<?php
$name = ? 
?>

Re: pull value from specific row in a table (MySQL query)???

Posted: Sun Jun 12, 2011 10:40 pm
by mathruD
nevermind. i got an answer from another forum. i ended up just creating a new query in which I did ORDER BY firstname DESC LIMIT. that gave me the last entry.