[SOLVED]pull value from specific row in a table

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
mathruD
Forum Newbie
Posts: 14
Joined: Thu Jul 23, 2009 2:58 am

[SOLVED]pull value from specific row in a table

Post 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 = ? 
?>
Last edited by califdon on Mon Jun 13, 2011 7:45 pm, edited 2 times in total.
Reason: In the future, please edit your own post and indicate that the problem has been solved. This time I have done it for you.
mathruD
Forum Newbie
Posts: 14
Joined: Thu Jul 23, 2009 2:58 am

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

Post 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.
Post Reply