0

I am using the following code

while($result1=mysql_fetch_assoc($sql))
{

    $result=$result1['userId'];
    $arr=explode(" ",$result);
    $userId=implode(",",$arr);
    echo $userId;
}

But I am getting the output like this:5354 I want my output 53,54 please help me

1

1 Answer 1

2

You first want to collect your values, which you fetch from your db, into an array. Then you want to implode() it.

while($result1=mysql_fetch_assoc($sql)){   
    $result[] = $result1['userId'];
}

echo implode(",",$result);

Right now in your code you simply explode one value into an array, but it can't split the string on the delimiter, so it just puts your value into the first array element.

Then imploding an array with only 1 element doesn't make much sense and you simply just output the value again in the while loop. So what your current code does right now is just:

while($result1=mysql_fetch_assoc($sql)){
    echo $result1['userId'];
}
Sign up to request clarification or add additional context in comments.

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.