forumnz Posted June 7, 2008 Share Posted June 7, 2008 I want to SELECT numbers FROM a database WHERE user='user'...I know how to do that... but lets say there is 5 rows with that user... how can I display the number from each one like this 1,2,3,4,5 ? Just the numbers with a comma in between? Hope this makes sense! Thanks! Sam. Quote Link to comment https://forums.phpfreaks.com/topic/109093-solved-displaying-numbers-from-rows-in-db/ Share on other sites More sharing options...
digitalgod Posted June 7, 2008 Share Posted June 7, 2008 $query = "SELECT...."; $result = mysql_query($query) or die(mysql_error()); while( $row = mysql_fetch_array($result) ) { echo $row['columnname']; } Quote Link to comment https://forums.phpfreaks.com/topic/109093-solved-displaying-numbers-from-rows-in-db/#findComment-559649 Share on other sites More sharing options...
forumnz Posted June 7, 2008 Author Share Posted June 7, 2008 Thanks..but what if I want it to be a variable? Like if in the end I want $numbers to equal '1,2,3,4,5'. How is that done? Quote Link to comment https://forums.phpfreaks.com/topic/109093-solved-displaying-numbers-from-rows-in-db/#findComment-559652 Share on other sites More sharing options...
digitalgod Posted June 7, 2008 Share Posted June 7, 2008 I'm not sure I understand what you mean, what columns are you selecting and what is it that you want to be displayed? Quote Link to comment https://forums.phpfreaks.com/topic/109093-solved-displaying-numbers-from-rows-in-db/#findComment-559653 Share on other sites More sharing options...
sasa Posted June 7, 2008 Share Posted June 7, 2008 $query = "SELECT...."; $result = mysql_query($query) or die(mysql_error()); while( $row = mysql_fetch_array($result) ) { $num[] = $row['columnname']; } $numbers = implode(',', $num); Quote Link to comment https://forums.phpfreaks.com/topic/109093-solved-displaying-numbers-from-rows-in-db/#findComment-559655 Share on other sites More sharing options...
digitalgod Posted June 7, 2008 Share Posted June 7, 2008 oh snap... I really am tired so yeah what sasa said should do the trick Quote Link to comment https://forums.phpfreaks.com/topic/109093-solved-displaying-numbers-from-rows-in-db/#findComment-559656 Share on other sites More sharing options...
forumnz Posted June 7, 2008 Author Share Posted June 7, 2008 Thanks everyone! Quote Link to comment https://forums.phpfreaks.com/topic/109093-solved-displaying-numbers-from-rows-in-db/#findComment-559659 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.