bradholland Posted June 26, 2008 Share Posted June 26, 2008 OK First off, Hi everyone, it's my first post, had a read of the rules etc hello and all that and had a good search on google and this seems to be the definative place to get answers and learn stuff! I am pretty much a total beginner, been watching a few course etc and working along although i wouldn't call myself a "total" noob, i can kinda read code and follow what it means to an extent. Which leads me to make this statement before i ask my question: at risk of offending the rules with my first post im not sure whether i should have posted this in the mysql help or the php help forums, so its not intentional if its in the wrong place, and i apologise in advance! ok. I'm playing about with a little db ive created. Im using a flash file to get the data outpuuted from this php file. I want to format the way the results are given to me in a different way. Heres just a little bit of the code and you can see basically what its doing. All pretty basic stuff I guess. while ( $i <= $numTracksToGet){ $row = mysql_fetch_array($result); extract($row); $echoString .= "&tracks_id=".$row['tracks_id']."&track_name="$row['track_name']";"; in that snippet of code before it loops round again it will display my results as &tracks_id=1;&track_name=test1;&tracks_id=2;&track_name=test2; something like that anyway. but what i want to do is display it like this: &tracks_id=1;2;3;&tracks_name=test1;test2;test3 so it returns all the track id's then all the track names etc etc Im not sure if i could have done this simply by changing the sql statement or if i should do this in the php code?? can anyone shed any light as to how i make the code to display the results like this. Thanks for reading my post Brad Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 26, 2008 Share Posted June 26, 2008 while($conditional==whatever) { $tracks_id.=$row['tracks_id'] . ";"; $tracks_name.=$row['track_name'] . ";"; $echoString=$tracks_id . "&" . $tracks_name; } ?> I believe that is what you're looking for Quote Link to comment Share on other sites More sharing options...
bradholland Posted June 26, 2008 Author Share Posted June 26, 2008 thanks for the reply mate. is it too much to ask you (if your feeling charitable) to talk me through whats happening there? I know its easy for me to copy and paste something like that, but i dont learn unless i understand what im doing. I dont want someone to just "give me code" (well it helps, but as i say....) thanks b Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 26, 2008 Share Posted June 26, 2008 <?php while($conditional==whatever) { // starts your loop $tracks_id.=$row['tracks_id'] . ";"; // puts your tracks id column values into a single string, adding onto each other separated by ; $tracks_name.=$row['track_name'] . ";"; // puts your tracks name column values into a string, adding onto each other separated by ; $echoString=$tracks_id . "&" . $tracks_name; // sets a variable with the previous two variables, separated by & } // after the loop is where you probably would want to echo $echoString ?> Quote Link to comment Share on other sites More sharing options...
bradholland Posted June 26, 2008 Author Share Posted June 26, 2008 Jabop, Your a total legend mate, thank you so much! Quote Link to comment Share on other sites More sharing options...
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.