Ted
Ted

Reputation: 3875

PHP MYSQL mysql_fetch_array, loop. right way to go?

I have a query that returns a few rows, and I have the following lines of code to retrieve them:

$result_set = mysql_query($query);

while($net_biz_sub_data[]=
 mysql_fetch_array($result_set,MYSQL_ASSOC));

My question is what is the right way to retrieve that db query data without getting the last array empty ? When I count() it is always num of rows + 1, and I would like to correct that.

Upvotes: 0

Views: 160

Answers (2)

Jan Dragsbaek
Jan Dragsbaek

Reputation: 8101

Because of the way the while loop works, you should do

while($dataz = mysql_fetch_assoc($result_set))
{
    $net_biz_sub_data[] = $dataz;
}

Upvotes: 7

genesis
genesis

Reputation: 50966

Use

$result_set = mysql_query($query);

while($net_biz_sub_data = mysql_fetch_assoc($result_set)){
    //use $net_biz_sub_data here
}

Upvotes: 1

Related Questions