Jump to content
xisto Community
Sign in to follow this  
it01y2

Php Explode Function Help

Recommended Posts

I am having trouble creating a script, all i want to achieve is to:

1. Select the variable from my mysql database, which is in a format of : id|id|id|id| and so on...

2. Split them into separate variables by using : $songexploded = explode("|",$ttyo['songs']);

3. Then this is the bit I'm stuck on trying to create a while loop from the $songexploded variables.

So(this might not be correct but you should get the idea)..

$x=1; while ($songexploded ==$result)echo $songexploded[$x].'<br>';}

Share this post


Link to post
Share on other sites

seriously, why use the while when you can use the foreach? for (and foreach), in my opinion, is more useful than while. php is supposed to make your life easier, you're not supposed to make it harder. anyway, try this:

 

$songexploded = explode("|",$ttyo['songs']);foreach($songexploded as $single) {  echo($single."<br />"); }

Share this post


Link to post
Share on other sites

seriously, why use the while when you can use the foreach? for (and foreach), in my opinion, is more useful than while. php is supposed to make your life easier, you're not supposed to make it harder. anyway, try this:

 

$songexploded = explode("|",$ttyo['songs']);foreach($songexploded as $single) {  echo($single."<br />"); }

Yes master_bacarra is right! That's the way I would've done it for sure! You beat me to it though.

Share this post


Link to post
Share on other sites

You forgot the if statement, but i would go with foreach too

 

if (case);

foreach (stufz){

do stufz

}

endif;

 

or you can use while with foreach if you need to loop through results

 

while (case)

foreach (stufz){

do stufz

}

endwhile

Edited by matak (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.