systemsgotyou Posted January 9, 2014 Share Posted January 9, 2014 Hello. I am new. I have simple two step process I want to be done. When it does work the webpage keeps going (im guessing it's an endless loop)... I can't seem to get it to work: I know there's something I'm missing about this PDO array stuff. <?php include("database.php"); $time_ago = strtotime("-1 minute"); /*find subscribers over a month old with the thirtydaysubs table*/ $checker = "SELECT emailaddress FROM aa_thirtydaysubs WHERE subscribedate < $time_ago"; $sthandler = $database->prepare($checker); $sthandler->execute(); /*then move it to main list and remove from 30 day list*/ $data = array(); $data = $sthandler->fetch(); if ($sthandler->columnCount()){ while($sthandler->fetchAll(PDO::FETCH_ASSOC) !== 0){ $email2 = $data->fetchColumn(0); $newlist= "2"; $updatelistid = "UPDATE zzemail_list_subscribers set listid = :newlist WHERE emailaddress = :email"; $sthandler3 = $database->prepare($updatelistid); $sthandler3->execute(array(':email' => $email2, ':newlist' => $newlist )); $clearars = "DELETE FROM aa_thirtydaysubs WHERE emailaddress= :email"; $sthandler6 = $database->prepare($clearars); $sthandler6->execute(array(':email' => $email2)); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/285232-so-confused-with-pdo-while-loop/ Share on other sites More sharing options...
Ch0cu3r Posted January 9, 2014 Share Posted January 9, 2014 (edited) fetchAll returns an array of results. You'll want to use a foreach loop instead foreach($sthandler->fetchAll(PDO::FETCH_ASSOC) as $data){ $email2 = $data['emailaddress']; $newlist= "2"; $updatelistid = "UPDATE zzemail_list_subscribers set listid = :newlist WHERE emailaddress = :email"; $sthandler3 = $database->prepare($updatelistid); $sthandler3->execute(array(':email' => $email2, ':newlist' => $newlist )); $clearars = "DELETE FROM aa_thirtydaysubs WHERE emailaddress= :email"; $sthandler6 = $database->prepare($clearars); $sthandler6->execute(array(':email' => $email2)); } If you used the fetch method then you'd use a while loop. Edited January 9, 2014 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/285232-so-confused-with-pdo-while-loop/#findComment-1464565 Share on other sites More sharing options...
systemsgotyou Posted January 9, 2014 Author Share Posted January 9, 2014 You are a godsend! So I keep the $data = array(); $data = $sthandler->fetch(); Right? Quote Link to comment https://forums.phpfreaks.com/topic/285232-so-confused-with-pdo-while-loop/#findComment-1464569 Share on other sites More sharing options...
Ch0cu3r Posted January 9, 2014 Share Posted January 9, 2014 You are a godsend! So I keep the $data = array(); $data = $sthandler->fetch(); Right? No, If you are using fetchAll then remove those lines. Quote Link to comment https://forums.phpfreaks.com/topic/285232-so-confused-with-pdo-while-loop/#findComment-1464570 Share on other sites More sharing options...
systemsgotyou Posted January 9, 2014 Author Share Posted January 9, 2014 Ok thanks dude! I owe you one! Quote Link to comment https://forums.phpfreaks.com/topic/285232-so-confused-with-pdo-while-loop/#findComment-1464571 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.