Jump to content

explode - implode - arrays.. help =)


Cyber

Recommended Posts

Hi.

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:
[code]
// 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

[/code]

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 =)

Cyber
Link to comment
Share on other sites

Yes okey..

Si if i do it this way..

[code]

<?php

    $puspus = explode(",",$sikkerhet);
    print_r($puspus);
    
?>  

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

[/code]

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