giraffemedia Posted August 15, 2008 Share Posted August 15, 2008 Hi i've got a mysql_fetch_array query that is returning results fine but i'd like to format the results a bit. At the moment i'm getting rows containing 62, 68, 67, 63, 66, 65 and 64 looking like 62686763666564. How can I turn them into 62, 68, 67, 63, 66, 65, 64 I've tried implode but it's not working properly. At the moment i'm getting the results in a while loop as there are many rows that need to be found for the query. Any ideas? Regards James Quote Link to comment https://forums.phpfreaks.com/topic/119850-solved-format-mysql_fetch_array-results/ Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 Show us your loop Quote Link to comment https://forums.phpfreaks.com/topic/119850-solved-format-mysql_fetch_array-results/#findComment-617439 Share on other sites More sharing options...
giraffemedia Posted August 15, 2008 Author Share Posted August 15, 2008 That might help he he! $issues_query = "SELECT * FROM issues_booked WHERE ib_booking_form_number = $bf_id"; $issues_result = mysql_query ($issues_query); while ($issues_row = mysql_fetch_array ($issues_result, MYSQL_ASSOC)) { $rows = $issues_row['ib_issue_number']; echo $rows . ' '; } Quote Link to comment https://forums.phpfreaks.com/topic/119850-solved-format-mysql_fetch_array-results/#findComment-617443 Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 OK, Heres your code $issues_query = "SELECT * FROM issues_booked WHERE ib_booking_form_number = $bf_id"; $issues_result = mysql_query ($issues_query); $data = array(); while ($issues_row = mysql_fetch_array ($issues_result, MYSQL_ASSOC)) { $data[] = $issues_row['ib_issue_number']; } print implode(", ", $data); Quote Link to comment https://forums.phpfreaks.com/topic/119850-solved-format-mysql_fetch_array-results/#findComment-617450 Share on other sites More sharing options...
giraffemedia Posted August 18, 2008 Author Share Posted August 18, 2008 Works a treat Neil thanks. All you're doing there is defining the $data variable as an array? Why is that necessary Neil? I tried using $data[] = $issues_row['ib_issue_number']; initially but because I didn't define the array first it didn't work. Do I have to do that every time I want to make a query an array? Regards James Quote Link to comment https://forums.phpfreaks.com/topic/119850-solved-format-mysql_fetch_array-results/#findComment-619018 Share on other sites More sharing options...
JonnoTheDev Posted August 18, 2008 Share Posted August 18, 2008 functions that accept arrays will cause an error if the value is not an array so it is always best to define the variable as an array. $data = array(); Quote Link to comment https://forums.phpfreaks.com/topic/119850-solved-format-mysql_fetch_array-results/#findComment-619026 Share on other sites More sharing options...
giraffemedia Posted August 18, 2008 Author Share Posted August 18, 2008 Ahh. Thanks for your help. James Quote Link to comment https://forums.phpfreaks.com/topic/119850-solved-format-mysql_fetch_array-results/#findComment-619045 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.