TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-19-2007, 01:39 AM   #1 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default [PHP/MySQL] Pulling Multiple Rows *Solved*

Solved. I'm an idiot, I forgot the most basic thing. :)

I haven't touched PHP in a while, and forgot most of the basics, which I'm going over by making small scripts at the moment. However, I'm stuck.

I have a MySQL database with 2 rows, each having 3 fields. What I'm trying to do, is get a resulting array from a query which will hold information from both rows, which are in the same field.

---------------------
| id | name | age |
---------------------
| 1 | Sally | 14 |
---------------------
| 2 | Mark | 13 |
---------------------

What I need, is to get for example, "Sally" and "Mark" in the same array so from there I can pull them apart and manipulate them for my objective.

How can I do this?
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Old 10-19-2007, 10:32 AM   #2 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

This would do the trick:

PHP Code:
$result mysql_query('SELECT name FROM table');
$aRow mysql_fetch_array($result); 
Also, you can use a while function to loop through the results, like this:

PHP Code:
while($row mysql_fetch_array($result)) {
  echo 
$row['name'];

maZtah is offline  
Reply With Quote
Old 10-19-2007, 11:50 AM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Lol, Andrew :) Glad you sorted it. It's all part of the learning process!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 10-19-2007, 07:10 PM   #4 (permalink)
The Acquainted
 
Join Date: Sep 2007
Location: Arizona
Posts: 114
Thanks: 10
Andrew is on a distinguished road
Default

Well, I knew about the while, but the wierd thing was when I dumped the mysql array I get from mysql_fetch_array(), the second row values didn't show up, so I assumed it didn't work (until I tried just doing the while statement).
Send a message via AIM to Andrew Send a message via MSN to Andrew
Andrew is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:37 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design