Jump to content

Simple loop/sql/array question


whit

Recommended Posts

Ok guys and gals I'm gettin' old! I know this is simple but I've spent way too much time on this now and am crying 'uncle'!

 

I'm trying load a multi-dementional array with mysql_fetch_array results but I'm not getting it. Here's the rough basis for what I'm trying to do:

 

$result = mysql_query("SELECT * FROM phpbb_profile_fields_data");
$row = mysql_fetch_array($result) or die(mysql_error());

$some_array = array(
    array(
        'member_name'  => $row['pf_firstname'] . " " . $row['pf_lastname'],
        'member_title' => $row['pf_title'],
        'member_employer' => $row['pf_employer'],
    ),
    array(
        'member_name'       => 'Janet',
        'member_title' => '47',
        'member_employer' => 'Husband',
        ),
);

 

Okay, so that loads two $some_array elements with data. The first element has the first row of the database in question. Works fine but useless.

 

So, with a "while ($row = mysql_fetch_array($result) )" what do I need to do to fill the $some_array with the query results?

 

Thanks!

 

Link to comment
https://forums.phpfreaks.com/topic/217383-simple-loopsqlarray-question/
Share on other sites

$some_array[] = 
    array(
        'member_name'  => $row['pf_firstname'] . " " . $row['pf_lastname'],
        'member_title' => $row['pf_title'],
        'member_employer' => $row['pf_employer']
    )

 

*clarification*

To display this:

foreach($some_array as $value) {
echo $value['member_name']; //etc.
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.