Jump to content

Search the Community

Showing results for tags 'opendir while loop'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Guest

    opendir and Loops

    I have 2 paces of code that work by themselves. But when I try to put 1 inside the other, it wont work. Basically, I want to bit the bottom code inside the top code where I have a comment "<!---SECOND CODE IN HERE--->": I have been working on this all day and now it's 5:17am. As far as I can work out, I think it has something to do with opendir twice.. because the codes work by themselves (I tested them).. but one wont work inside the other. I am completely out of ideas I know you can put a loop n a loop because I tested it. I think it's the opendirs. I get the error: Warning: readdir(): 372 is not a valid Directory resource 1st code: $dir = '/home/tool/public_html/referrals_bridge/'; if ($handle = opendir($dir)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != ".." && $entry != ".php" && $entry != ".txt" && $entry != "error_log") { //echo "$entry\n"; $affiliate_id = file_get_contents($dir . $entry); $user_id = $entry; //echo "Referral ID:" . $affiliate_id . "<br />"; $user_id = str_replace('.txt', '', $user_id); echo "User ID:" . $user_id . "<br />"; //$user = $entry; //$user_role = file_get_contents('/home/tool/public_html/referrals/'.$affiliate_id.'/role.txt'); //exit; //Get user information $user_info = get_userdata($user_id); $paypal_email = $user_info->paypal_email; $contact_email = $user_info->user_email; $user_role = implode(', ', $user_info->roles); echo $user_role . "<br />"; $user_role =preg_replace('/^([^,]*).*$/', '$1', $user_role); <!---SECOND CODE IN HERE---> echo '<table summary="" cellpadding="0" cellspacing="0" border="1" style="font-size: 12px; font-family: arial"><tr>'; echo '<td>ID</td><td>Role</td><td>Aff ID</td><td>Refs</td><td>Free</td><td>VIP</td><td>Commission</td><td>email</td></tr><tr>'; echo '<td nowrap>'.$user_id.'</td>'; echo '<td nowrap style="width: 200px;">'.$user_role.'</td>'; echo '<td nowrap>'.$affiliate_id.'</td>'; echo '<td nowrap>'.$totalMembers.'</td>'; echo '<td nowrap>'.$UnSubscribedMembers.'</td>'; echo '<td nowrap>'.$SubscribedMembers.'</td>'; echo '<td nowrap><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business='.$paypal_email.'&item_name=toolHost+Commission&item_number='.$user_id.'&currency_code=USD&lc=CA&charset=UTF%2d8&amount='.$referral_commissions.'" target="_blank">'.$referral_commissions.'</a></td>'; echo '<td nowrap><a href="mailto:'.$contact_email.'&subject=Re: toolHost Commissions">contact</a></td>'; echo '</tr></table>'; } } closedir($handle); } 2nd code: // initialize counters to zero $SubscribedMembers = 0; $UnSubscribedMembers = 0; //$current_user = wp_get_current_user(); $dir = '/home/tool/public_html/referrals/' . basename($affiliate_id); if ($handle2 = opendir($dir)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != ".." && $entry != "role.txt"&& $entry != "promos") { //echo "$entry\n"; $path = "$dir/$entry"; $result = file_get_contents($path); switch(trim($result)) { // increment subscribed couter, if the contents of the file is "subscribed" case 's2member_level2': $SubscribedMembers++; break; // increment unsubscribed couter, if the contents of the file is "unsubscribed" case 's2member_level1': default: $UnSubscribedMembers++; break; } } } closedir($handle2); } // calculate total members $totalMembers = $SubscribedMembers + $UnSubscribedMembers; // output results $referral_commissions = ($SubscribedMembers * '7.5'); //clean up long names: if ($user_role == "subscriber") { $user_role = "Free"; } if ($user_role == "s2member_level1") { $user_role = "Entrepreneur"; } if ($user_role == "s2member_level2") { $user_role = "VIP"; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.