greenday Posted October 3, 2008 Share Posted October 3, 2008 I have a while loop like this: <?php do { ?> <?php echo $row_mapdirections['name']; ?>@<?php echo $row_mapdirections['lat']; ?>, <?php echo $row_mapdirections['lon']; ?> to: <?php } while ($row_mapdirections = mysql_fetch_assoc($mapdirections)); ?> This will ouput something like: Name@lat, lon to: Name@lat, lon to: Name@lat, lon to: How can I store the above output as a vairable? The reason i want to to do this is to echo the result later with a right trim on to remove the unwanted 'to' at the end. Thanks! Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 3, 2008 Share Posted October 3, 2008 No need to trim anything <?php while ($row_mapdirections = mysql_fetch_assoc($mapdirections)) { $outputAry[] = $row_mapdirections['name'] . '@' . $row_mapdirections['lat'] . ', ' . $row_mapdirections['lon']; } echo implode(' to: ', $outputAry); ?> Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 3, 2008 Share Posted October 3, 2008 No need to break in and out of PHP like that. <?php $output = array(); do { $output[] = $row_mapdirections['name']."@".$row_mapdirections['lat'].", ".$row_mapdirections['lon']; } while ($row_mapdirections = mysql_fetch_assoc($mapdirections)); echo "<pre>", print_r($output), "</pre><br />"; //Now to seperate with to? echo implode(" to: ", $output); ?> Edit: mjdamato got it. Quote Link to comment Share on other sites More sharing options...
greenday Posted October 14, 2008 Author Share Posted October 14, 2008 Sorry for the REALLY late reply, got so busy, and then couldnt find this post in the forum. The first suggestion works good, but removes the whole last loop, not just the last "to:" The second suggetsion works perfectly. The only main differance I can see is the second suggestion echos out the output with <pre>? Anyway thanks very much for your help, it solved my problem 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.