|
|
 |
| Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning PHP section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

July 11th, 2004, 08:40 PM
|
|
Authorized User
|
|
Join Date: Aug 2003
Location: Coeur d\'Alene, ID, USA.
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
getting a specific row from a MySQL result set
I'm having trouble getting my program to select a specific row from a MySQL result set. I know how to fetch the first row from a result set and I know how to print out the entire result set but that's about all I can do with it.
My situation is this: the program runs a query and grabs all the rows from a table (skill_info) where Joe has a listed skill. The result set has 3 rows and one of those rows is Joe's skill in carpentry. I want to grab that row and put it into $row[].
I thought of trying this:
Code:
mysql_data_seek ($result, 0);
while ($row = mysql_fetch_array($result)){
extract($row);
if ($row['skillnum'] == "54"){
exit;
}
}
but it exits the whole script/program when I only want to exit the loop.
Can anyone help? There must be a way to make mysql_fetch_array fetch only the row I want.
__________________
An overworked Web Developer who\'s expected to know everything yet given time to study nothing.
|

July 12th, 2004, 06:07 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
A number of point sripng to mind.
a) To exit a loop, use "break".
b) the resultset is just a PHP array, so you can treat it as such by using array-handling functions like in_array() or array_search(), and so on.
c) Why don't you add a test for "WHERE skillnum='54'" in you original query :)?
Take it easy,
Dan
|

July 12th, 2004, 10:39 AM
|
|
Authorized User
|
|
Join Date: Aug 2003
Location: Coeur d\'Alene, ID, USA.
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks for the info. I know what to try out now.
My situation is this: I've got a page that displays information on 7 different skills. Rather than query the database 7 times I want to do it once and use the result set 7 times.
|

July 12th, 2004, 12:55 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Yes, that certainly makes sense, and it's something I do a lot of - especially when the results come form massive correlated subqueries. Like I say, you can handle the resultset as what it is: an associative array (at least, it's associative, if that's how you have fetch_array set to work, which from my reading you code abovce, I take it it is).
Take it easy,
Dan
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |