Strange array issue, never happened before.


Posted on 16th Feb 2014 07:03 pm by admin

mysql_fetch_array returns 1 array per call. Generally that's why it is inserted into a while statement. I generally loop through them in a while statement and put them all in a master array so I have all the results in one place instead of having to use them on the spot in the while loop. So here is what I generally do:
// If the flag all is set then run an "all" query. else we need to do some specifics on the query instead.
Code: [Select]<?php
if ($flag['all'] == 1) {
$sql = 'SELECT * FROM data_resources';
}else {
$sql = '';
}

#### Run Query ####
$data = array(); //This is the master array that will contain all results.
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
$data[] = $row;
}
?>
If I echo out the data array inside the while statement it works properly, but when I try to access it outside of the while it doesn't work. What is going on? Normally this works just fine.

No comments posted yet

Your Answer:

Login to answer
272 Like 45 Dislike
Previous forums Next forums
Other forums

array_combine() error
getting an "Warning: array_combine() [function.array-combine]: Both parameters should have an e

How to show the difference between two data field in a database with php.
Hello php gurus,

how r u all... i'm not so well facing a typical problem please help me...<

How to show a complete textarea ??
I enter Client Case Notes notes in a textarea field on a PHP form. The field is 5 rows deep and 70 c

Thought I has this figured out especially after all the help i received?
Cags, Salathe, Daniel helped me with this yesterday, but not sure i took it all in.
I am attempti

Basic Question about Threading and PHP...
I have a page that I am working on and it is taking several hours to process. The basics of what th

Writing Windows Device Drivers with C
Yes: one of the nice features of C is void*. You can put anything there and get anything out. Very

What's best way to get a user's Word doc converted to simple html and images?
Hi all,

I was just wondering if anybody has any experience of this.
Basically, I'm buildin

form variables from database help.
Hi all,

I would like to have a form that gives you options based on the results of an mysql q

undefined offset help
Hi All,

I kept getting undefined offset PHP notice for a simple for loop. For eg
$va = arr

Curl timeout breaks script
So im having difficulties with skipping timeout error in curl
my script calls different functions

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash