0

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.

2
  • The return value of count() is accurate. Arrays are zero indexed. Use < count() instead of <= count(). Commented Oct 3, 2011 at 18:13
  • -0.25 for still using mysql_query. What half-assed site/book/whatever is presenting that as an example of modern best practices? Commented Oct 3, 2011 at 18:14

2 Answers 2

7

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

while($dataz = mysql_fetch_assoc($result_set))
{
    $net_biz_sub_data[] = $dataz;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Use

$result_set = mysql_query($query);

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.