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

Problem with an browser game.
Hello,i just joined that great forum and i got php prob,its kinda freaky...anyway i got browser game

trouble printing an array....
I'm having some trouble printing out an array forwards. I'm figuring out the high and low of an arra

Add weeks in a query?
I have a SQL that summarizes the quantity per week. The weeks that has no value does not exist in th

Help With editting and deleting form
Hallo !!

So look at this image :

http://img194.imageshack.us/img194/8272/snapshot5f.pn

$_POST
Hi, I have 2 seperate php files, and i want my $_POSt["fname"] To go into both of them, Fo

gettext translates ALWAYS?
I'm using gettext with the new version of XAMPP (5.3.0) on Windows Seven RTM (build 7600)
gettext

PHP mail() returns true but doesn't work
First off I apologize if this is a newbie question, and I generally don't like asking questions that

How to use php and sql to check if values match the ones in a table (for logins)
How would I code it that the script takes two variables that are passed to it (UserID and PIN), and

Storing the referrer in session... problems with tabs
Hello All

I am currently working on an ERP project based on the MVC methodology, when a user

read integers that returns a negative or prints the average
Im trying to finish this homework assignment by tommarow afternoon and I keep getting stuck.
Wr

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