0

thanks guys..

please clear one more doubt..

lets say, i have a table(Name) with fields first_name, mid_name and last_name. records in the table are as follows:
1. tom-robert-hanks
2. angel-diva-hanks
3. nick-kick-hanks
4. jingle-doll-bond
5. james-cool-bond
6. john-mac-bond

now i want to fetch all the first_name having last_name as bond into a array.

PHP Syntax (Toggle Plain Text)
$query="select * from Name where last_name='hanks'";
$result=mysql_query($query);
$row=mysql_fetch_array($result);

now, what will be there with $row, is it just the 1st row containing hanks??
how do i access the next two names..

pls clear this for me..it may sound silly but really confusing me..

thannks

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by puvi
0

Hi puvi,

Place the mysql_fetch_array function as the condition of a while loop.

while ($row = mysql_fetch_array($result))

each cycle through the loop will populate the $row array with data from the next matching database row.

As a side note, if you only need to fetch the first name from the database, you could specify this in your SQL.

$query="SELECT first_name FROM Name WHERE last_name='hanks'";

Hope this helps.
Zagga

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.