TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   [PHP/MySQL] Pulling Multiple Rows *Solved* (http://www.talkphp.com/general/1318-php-mysql-pulling-multiple-rows-solved.html)

Andrew 10-19-2007 01:39 AM

[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?

maZtah 10-19-2007 10:32 AM

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'];



Wildhoney 10-19-2007 11:50 AM

Lol, Andrew :) Glad you sorted it. It's all part of the learning process!

Andrew 10-19-2007 07:10 PM

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).


All times are GMT. The time now is 01:30 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0