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;

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.