/    Sign up×
Community /Pin to ProfileBookmark

How to loop through a date range of each id coming from the database

Hello everyone . So i an issue with two arrays going into one url endpoint.
I have three properties

  • 1. a url endpoint that accepts two query parameters $id and $$timestamp $apiUrl=”https://api.bravenewcoin.com/v3/index-ticker?indexType=GWA&indexId=$id&timestamp=$timestamp “;

  • 2. $Id is the id of different accounts in a database table

  • 3. $timestamp is a date range specified by users. This range starts from the current system time to a set enddate.
    the api gets all activities of each account id based on the set timestamp.

  • 4. what i want now is how to get all activities of each account id based on the set timestamp

  • 5. i Know i will end up with two foreach loop. how do i loop through the date range of each ID
  • method to get time range

    public function loopThroughRange($date2,$date1){
    // echo $enddate;
    $date2=date(‘Y-m-d H:i:s’);
    if ( $date2 > $date1) {
    $start = new DateTime($date2 );
    $end = new DateTime($date1);
    $diff = $end->diff($start);
    $interval = DateInterval::createFromDateString(‘-1 day’);
    $period = new DatePeriod($start, $interval, $diff->days)
    foreach ($period as $date) {
    return $date->format(‘y-m-d h:i:s’) . ‘<br>’; // or whatever you want to do
    }
    }

    method to get all Account id from the database

    public function getIndexID(){
    $query=’ SELECT ‘.ACTIVE_ID.’ FROM ‘.ACTIVECURRENCY_TB.”;
    $sth =$this->conn->prepare($query);
    $sth->execute();
    $indexId = $sth->fetchAll(PDO::FETCH_ASSOC);
    return $indexId;
    }

    to post a comment
    PHP

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @NogDogNov 22.2019 — Unless I'm missing something, why not add the date range to the query?
    <i>
    </i>SELECT ... WHERE some_datetime_column BETWEEN '2019-10-01T00:00:00' AND '2019-12-31T23:59:59'

    (Presumably replacing the date/time strings with prepared query place-holder then binding the desired variables with start and end timestamps)
    ×

    Success!

    Help @charles_D_PHP_BENDER spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 4.26,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...