0

The field: Friends, and contains something like "2,3,6,3,67,97" the numbers are user ID's.

i want to know if there is a way to get those numbers into an array?

Thanks in advance

2
  • What is wrong with php.net/explode ? Commented Mar 10, 2012 at 15:23
  • 1
    As a side note: Having a field like this is a bad idea in 99% of all cases. Look into database normalization and create a table like CREATE TABLE friended_user ( user_id INT, friended_user_id INT) and do some JOINs Commented Mar 10, 2012 at 21:28

2 Answers 2

2

Use explode() method

$data = "2,3,6,3,67,97";
$dataarray= explode(",",$data);
Sign up to request clarification or add additional context in comments.

Comments

1

You could do something like

$counter = 0;
$array = array();
while($row = mysql_fetch_array($sql)) {
    $array[$counter] = explode(",", $row['friends']) // or whatever the column is called
    $counter++;
}

So for the first entry in the database,

$array[0][0] = 2
$array[0][1] = 3 // etc etc...

Apologies if the code is wrong, been a while since I've worked with multi-dimensional arrays. Hope the concepts helped though :)

Comments

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.