it01y2 0 Report post Posted July 17, 2007 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
matak 2 Report post Posted July 17, 2007 Try $x=1;while ($songexploded == $result ){echo $congexploded[$x]. '<br>';$x++;} Share this post Link to post Share on other sites
master_bacarra 0 Report post Posted July 17, 2007 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
reconraiders 0 Report post Posted July 17, 2007 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
matak 2 Report post Posted July 17, 2007 (edited) 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 July 17, 2007 by matak (see edit history) Share this post Link to post Share on other sites