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) {
Did you know?Explore Trending and Topic pages for more stories like this.
$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

Problem with Sending Mail by PHP
hello all,
I m new to php, can u plz provide me the code to send mail by php having CAPTC

UPLOAD IMAGES NOT WORKING!
Hi there i have a upload script in which it uploads the picture to a folder than creates two thumbna

Save User Inputs while javascript reloading!
hi..
i have written a PHP code in which i reload the page when user selects a value in dropdown..

Request.UrlReferrer
I need to make it so that a page can only be loaded when a button is clicked on a specific page. I d

Calling a Procedure with IN & OUT Parameters
Hello,

I usually call my procedures using the following way

declare variable e

Solution to the FindControl problem
I have seen may posts about having problems with the FindControl method. Most seem to come about bec

SESSION CHECK WORKS "MOST" of the time... whats going on?
i have a sign in check thats included in every page that is a members only page which is basically a

Sendmail.php - heading error following check_input
Hi,

I would greatly appreciate some help? I am brand new to PHP and have been searching and e

dropdown box help - open php files to textarea
Hi, I am using tinymce to edit content located in several php files. The code I attached works but i

search function
HI guys,

if anyone could point us in the right direction of how to do this, or provide some t

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