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

phph within href not showing php if change ? to &
Code: [Select]<a href="<?php echo $puser; ?>?m=<?php=(($m-1)&l

Do While statement
hi guys,

This may sound trivial but im new to php and as part of an assignmenti have to const

How to generate a random array of integers subject to a certain constraint
I am writing a program that asks the user to enter an integer N and then generates a random array of

is_dir() problem
Hello,

I'm buidling a php scripts that dynamically get's subfolders from a specific folder.

New to PHP and just trying to understand a little code.
I hope I'm not annoying anyone or breaking the rules but I was wondering about this bit of code righ

How to make a input/output field with multiple lines
Hello.
I put a input/output field on the screen but I could not change height of it. I need to

Request for tunning the below query
Hi,

Can any one help me on the below query while improving the performance,

How to make URL loads only on login
On my page, when a user login he's redirects to user_home.php. I made it also to open the chat scree

Array to string conversion
Can anyone help me with this?

Notice: Array to string conversion in /home/..../index.php on l

Multiple server callbacks (NOT POSTBACKS)
Hello, I have 2 different javascript client side functions that are on timers. When the timers elap

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