1

Basically I want to take 4 of the 16 columns; id,username,country,signupdate; in my table and make an array of arrays out of them.

mysql table

I have a basic grasp on the concept, grab a row and place in an array, then the next one, and so on. then put the arrays in an array.

Only one problem. I have absolutely no idea how to do this. I just started learning in php and mysql, so please be patient. Thanks in advance!

2
  • 2
    What do you have so far? Commented May 4, 2012 at 21:29
  • Well, I found this but I'm confused on how to use it: $sql = mysql_query("SELECT username,id,signupdate,country FROM members"); $result = mysql_query($sql); $content = array(); while($row = mysql_fetch_assoc($result)) { $content[$row['id']] = $row; } Commented May 4, 2012 at 21:33

1 Answer 1

1

It should do that automatically for you:

$query = mysql_query("SELECT `id`,etc");
while( $row = mysql_fetch_assoc( $query ) )
{
  echo $row['id'];
  echo $row['etc'];
}

That will give you each row of your 'associative array'. Or, you can make a big associative array:

$bigArray = array();
$query = mysql_query("SELECT `id`,etc");
while( $row = mysql_fetch_assoc( $query ) )
{
  $bigArray[] = $row;
}

print_r($bigArray);
Sign up to request clarification or add additional context in comments.

3 Comments

... I need it for listing the members on the "member yellopages" and I'm still confused
@iPElectronics: I'm not sure why their stylesheet is messed up, but you need to read this before you go any further. It sounds like you're not up to speed on what you're really doing: php.net/manual/en/book.mysql.php
I think I understand now, my next issue is using a foreach loop to grab the first row and use those vars then grabbing the next row, using those and so on until there are no more rows

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.