Jump to content


Photo

explode - implode - arrays.. help =)


  • Please log in to reply
4 replies to this topic

#1 Cyber

Cyber
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 10 March 2006 - 10:15 PM

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

Cyber

#2 CyrusTh3VIrus

CyrusTh3VIrus
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 10 March 2006 - 10:23 PM

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

#3 Cyber

Cyber
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 11 March 2006 - 02:21 PM

Yes okey..

Si if i do it this way..


<?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


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

#4 Cyber

Cyber
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 11 March 2006 - 09:22 PM

anyone ?

Please !!

Thanks

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 12 March 2006 - 02:14 AM

Please post any code you have to show what your're trying to do.

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users