Jump to content

So confused with PDO while loop


systemsgotyou

Recommended Posts

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));
}
}
?>
Link to comment
Share on other sites

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 by Ch0cu3r
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.