Jump to content

PDO on Foreach x IF Condition


ajmeireles

Recommended Posts

Hi, everyone, someone can help me?

I need to get all parameters from tblhosting table from a specific client that have the domainstatus as ACTIVE.

I'm trying with this code:

Quote

    $pdo = Capsule::connection()->getPdo();
    
    $pdo->beginTransaction();
    
    $service = $pdo->prepare("SELECT userid, packageid, nextduedate, amount FROM tblhosting where domainstatus = Active");

    $service->execute();
    
    $row = $service->fetchColumn();
    
    if($row->userid == 1)
    {    
        //... working here
    }

But isn't work if the user is really the userid 1.

I know that is easy to do using foreach, for example:

Quote

    $pdo = Capsule::connection()->getPdo();
    
    $pdo->beginTransaction();
    
    $service = $pdo->prepare("SELECT `userid` as `id`, `packageid` as `produto`, `nextduedate` as `vencimento`, `amount` as `value` FROM `tblhosting` WHERE `domainstatus` = 'Active'");

    $service->execute();
    
    $pdo->commit();
    
    foreach($service AS $dados)
    {
        //... working here
    }

For example, if I send a mail using localApi in foreach, the system will send more than 1 mail if the client have more than one actived service, due the foreach.

Someone know some method to get all parameters from tblhosting and use it on single variable in a simple if condition?

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated