Guest Drizzle Posted April 5, 2010 Posted April 5, 2010 Ok, so im trying to explode an array of items, split by a comma ",",so heres the code im using: $items - explode(",",$r['cITEMS']); echo $items[0]; Now i know that wont print the name, but how can i get it so both my items show up, instead of just 1? Quote
Djkanna Posted April 6, 2010 Posted April 6, 2010 As far as I know if you're using an array() you'd get an array to string PHP notice :-/ $list = "One,Two,Three"; // List // Explode $getList = explode(",", $list); echo $getList[0]; // One echo $getList[1]; // Two echo $getList[2]; // Three Hope this helps somewhat. Quote
Guest Drizzle Posted April 6, 2010 Posted April 6, 2010 What i originally was looking for was, how to explode by ",", from a list of id's, and then print the individual item names. I achieved this with foreach(), moments after the post. but thanks anyway :) Quote
Dayo Posted April 6, 2010 Posted April 6, 2010 $items - explode(",",$r['cITEMS']); echo $items[0]; try the one below you put - not = $items = explode(",", $r['cITEMS']); echo $items[0]; Quote
CrazyT Posted April 6, 2010 Posted April 6, 2010 Why should i help you when you keep sending e-mails from my e-mail to other people. IE: Pudda, and same to Pudda to me? Are you a idiot? I'm sure you are. But here anyway. $names = "a,b,c,d,e,f,g,h,i"; $names = explode(",", $names); echo "<pre>"; print_r($names); echo "</pre>"; Now you would have something like: array ( 0 => 'a', 1 => 'b', 2 => 'c', 3 => 'd', 4 => 'e', 5 => 'f', 6 => 'g', 7 => 'h', 8 => 'i' ); Now to get f you would need to do. echo $names[5]; Done :) Quote
Zero-Affect Posted April 6, 2010 Posted April 6, 2010 $items - explode(",",$r['cITEMS']); foreach ( $items AS $key ) { echo $key.' '; # You could also input a query or whatever you want in here # mysql_query('UPDATE `table` SET `column` = "Set Variable" WHERE `column` = '.$key.', $connect); } ... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.