Jump to content

[SOLVED] Array query only returning one row?


giraffemedia

Recommended Posts

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;

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.