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; Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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~ Quote Link to comment 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 Quote Link to comment 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... 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.