giraffemedia Posted August 12, 2008 Share Posted August 12, 2008 Hi guys i'm trying to echo the results of a mysql query, but when I use implode to expand the array as a string it's only returning one row when there should be seven. Any body have any idea what might be the cause. Here is my code... // Get the booking id from the URL $bf_record = $_GET['bf_id']; // Define the db query $issues_query="SELECT * FROM issues_booked WHERE ib_booking_form_number = $bf_record"; // Define the rquery result $issues_result = mysql_query($issues_query); // if no result echo why if(!$issues_result) { echo("Query Error: ".mysql_error()); } // While loop to define array results while($row = mysql_fetch_array ($issues_result)) { $votes_array = array("votes" => $row['ib_issue_number']); } // Break the array into a string $test = implode(',', $votes_array); // print the results echo $test; Link to comment https://forums.phpfreaks.com/topic/119284-solved-array-query-only-returning-one-row/ Share on other sites More sharing options...
trq Posted August 12, 2008 Share Posted August 12, 2008 You keep overiding $votes_array['votes'] in each iteration. Use... $votes_array[] = $row['ib_issue_number']; instead. Link to comment https://forums.phpfreaks.com/topic/119284-solved-array-query-only-returning-one-row/#findComment-614461 Share on other sites More sharing options...
giraffemedia Posted August 12, 2008 Author Share Posted August 12, 2008 You keep overiding $votes_array['votes'] in each iteration. Use... $votes_array[] = $row['ib_issue_number']; instead. Of course Thanks a lot thorpe, that works great. James Link to comment https://forums.phpfreaks.com/topic/119284-solved-array-query-only-returning-one-row/#findComment-614462 Share on other sites More sharing options...
discomatt Posted August 12, 2008 Share Posted August 12, 2008 Also, just a little advice... If you only need one column, why are you forcing mysql to grab every column in the table? Even using SELECT * requires more work than SELECT `all`, `the`, `columns`, `in`, `the`, `table` because it forces MySQL to grab a list of columns and then perform the query. Change SELECT * FROM issues_booked WHERE ib_booking_form_number = $bf_record to SELECT `ib_issue_number` FROM issues_booked WHERE ib_booking_form_number = $bf_record It will also save a bit of memory, as no unused values are created when calling mysql_fetch_array. Link to comment https://forums.phpfreaks.com/topic/119284-solved-array-query-only-returning-one-row/#findComment-614481 Share on other sites More sharing options...
Jabop Posted August 12, 2008 Share Posted August 12, 2008 Maybe he plans on using every single column selected, and * may work to his needs~ Link to comment https://forums.phpfreaks.com/topic/119284-solved-array-query-only-returning-one-row/#findComment-614492 Share on other sites More sharing options...
giraffemedia Posted August 12, 2008 Author Share Posted August 12, 2008 Also, just a little advice... If you only need one column, why are you forcing mysql to grab every column in the table? Even using SELECT * requires more work than SELECT `all`, `the`, `columns`, `in`, `the`, `table` because it forces MySQL to grab a list of columns and then perform the query. Change SELECT * FROM issues_booked WHERE ib_booking_form_number = $bf_record to SELECT `ib_issue_number` FROM issues_booked WHERE ib_booking_form_number = $bf_record It will also save a bit of memory, as no unused values are created when calling mysql_fetch_array. Thanks for the advice Matt, i'll change it now. James Link to comment https://forums.phpfreaks.com/topic/119284-solved-array-query-only-returning-one-row/#findComment-614502 Share on other sites More sharing options...
discomatt Posted August 12, 2008 Share Posted August 12, 2008 Maybe he plans on using every single column selected, and * may work to his needs~ Hence the If And IMHO, SELECT * is lazy programming, and should never be used in a production environment... Link to comment https://forums.phpfreaks.com/topic/119284-solved-array-query-only-returning-one-row/#findComment-614518 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.