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

Link to comment
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']
    )

 

omg! Put that inside the loop?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.