Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Thanked 20 Times in 20 Posts

    couple of questions

    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?
    Last edited by c1lonewolf; 10-25-2012 at 09:03 PM.
    NO Limits!! DHCreationStation.com
    For projects using MediaTypes (MIMETypes) visit E-BAM.net -(updated weekly)

    Broken items wanted for tinkerin'! PostItNow@BrokenEquipment.com
    Global Complaint Dept.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,662 Times in 2,631 Posts
    1. 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.
    2. 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.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts