Jump to content


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


explode - implode - arrays.. help =)

Recommended Posts


I`m trying to understand and use explode(), implode() from and to mysql db.
Can someone SHOW me how to do the following code ??
Please ?

This is what i use to get the info into the db:
// This is a checkbox from a form

echo '<input type="checkbox" value="'.$id.'" name="comfy[]"'; if(array_search("1",$comfy) > -1) echo ' checked="true"'; echo '>'.$cars_comfy.'<br>';

//After submitting the form, i use implode

$comfy= implode(',',$comfy);

// That works okey enough, and in db it shows 1,2,3,4,5,6 and so on


But then comes the tricky part, how to get it out again!?

Thing is, that i am storing only numbers (like 1,2,3), and the value of those numbers is stored into another table.

tablename: cars
row[0]: cars_id
row[1]: cars_comfy

So you see that, i have to get out the numbers from the first table then the cars_comfy (output these names) to match the cars_id that is already uses implode on.

Output would be (like i want it to be): A list:

* carname1
* carname2
* carname3
* and so on....

Anyone that can help me make this script ??
Much easier to see a working example that reading from a text book.. hehe..

Anyway, thank you so much =)


Share this post

Link to post
Share on other sites
If you would make it an array again you just have to use explode(',',$comfy);
If $comfy is 1,2,3,4,5 the return of explode(',',$comfy); would be array(1,2,3,4,5);
I hope this helps

Share this post

Link to post
Share on other sites
Yes okey..

Si if i do it this way..



    $puspus = explode(",",$sikkerhet);

Then this will output this:

Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 )

Cuz in db row it is inserted value 1,2,3,4,5,6,7,8


But how to use these values ?

That array is the ID to the value to another table in db, example 1 = Golf, 2 = BMW etc.

So then i need a sql_query that get`s the value from both tables and out puts it like a list as wanted.

But please show me how.. I do not know at all, tried to read it several times.. I know it is simple, but i can`t get it right.. please help..

Thanks again.

Share this post

Link to post
Share on other sites
Please post any code you have to show what your're trying to do.


Share this post

Link to post
Share on other sites


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.