View Full Version : couple of questions

10-25-2012, 09:00 PM
Just a couple of questions...

function pull_Files($dir){
$FileList = array();
$dh = opendir($dir);
while(! is_bool($file = readdir($dh) ) ){
if( is_file( "$dir$file" )){ $FileList[] = "$file"; }
return $FileList;

1. The function above doesn't return the file array back to the caller. What's wrong with it? If I use the $FileList as a global and update it that way it works.

2. After retrieving items from the database I can use:
while ($row = mysql_fetch_assoc($array)) {

But I need to use something like:
$row = mysql_fetch_assoc($array[$x]);

Like javascript to retrieve the id of the record before and after. Problem is the for loop doesn't work. How do I fix it?

10-25-2012, 10:44 PM
Show an example of the usage of the function pull_files. If it doesn't work with a return, but it does work with a global, this indicates to me that you are incorrectly using the function itself in assignment and handling of the variables for the caller. Scandir or glob may be easier; it won't work with just files, but if all your files have extensions than global can use *.* (although .htaccess for example would not match). You can also walk them after or use a filter.
I won't suggest that extract is the best thing to use. Without a prefix modifier its far too easy to overwrite variables with no warning. However, short answer is you cannot. Resources cannot be treated as an array; you may use a data seek method to choose the row you want first, then execute a fetch, or dump the entire resultset into an array. If the second block of code were valid, there would be no difference in the output. They both contain single variables representing the last record in the resultset.