Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8186967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:24:14+00:00 2026-06-07T02:24:14+00:00

I am working on a project in which i have to distribute different ad’s

  • 0

I am working on a project in which i have to distribute different ad’s per day, the ad’s in form of array are:

$ad = array( 'attribute1_value' => "12",
 'attribute2_value' => "xyz",
 'attribute3_value' => 'http://example.com',
 'attribute4_value' => 'data');

The logic i am using with switch case :

$day = date('w',time());

    switch ($day) {
        case '0':
        if($day == '0') {
            $count = 0;
            echo $ad;
            $count++;
        }
        else {
            $count = 7;
            echo $ad;
        }
        break;

            case '1':
        if($day == '1') {
            $count = 1;
            echo $ad;
            $count++;
        }
        else {
            $count = 8;
            echo $ad;
        }
        break;

Problem is if i have ~15 ad’s then i want to distribute ad/day, date(‘w’) output’s the present day but after day 7 i.e saturday, on sunday ad number 8 initiate. I have to implement this scenario using date function. Also i have to send ad’s to those user who are not experience this ad before. I am not expert in php, as a beginner working in php/mysql. Kindly help me to improve this concept

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:24:16+00:00Added an answer on June 7, 2026 at 2:24 am

    There’s some issues with your current code. First, with logic:

        case '0': //<!-- ensures the following code executes only where $day == 0
        if($day == '0') { //<!-- therefore this will run
            $count = 0;
            echo $ad;
            $count++;
        } else { //<!-- but this can never run
            $count = 7;
            echo $ad;
        }
    

    Also, you’re echo’ing out $ads, which is an array. You need to echo out an element from the array.

    If you want one Monday to use ad 1 and the following Monday to use ad 8, date('w') isn’t going to be much help as that simply cycles through 0 to 6, so it is unsuitable for this. It has no memory of the overall day number of the month or year – its scope is only the current week.

    You could use the day of the month instead [edit – or, of course, the day of the year (date('z')). See comment underneath).

    $day = date('d');
    $ads = array('ad 1', 'ad 2', 'ad 3', 'ad 4', 'ad 5', 'ad 6', 'ad 7', 'ad 8', 'ad 9', 'ad 10', 'ad 11', 'ad 12');
    echo $ads[($day - 1) % count($ads)];
    

    So on the 5th day of the month, ad 5 shows. On the 7th day, ad 7 shows. On the 14th day, ad 2 shows, as it starts round the ad cycle again.

    As for how to ensure a user has not seen the ad before, that’s a whole other question and I suggest you post it as such. This would presumably involve some sort of cookie system, unless users are logged in, in which case you could track this sort of thing server-side.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a hobby project in which I have to crawl different
I'm working in a Yii project which also have a console application. Form the
I'm working on a project in which we have a database, data layer (entity
hello all i am working on a project in which i have a webpage
My problem/issue We are working on an opensource project which we have hosted on
I'm working on a project which will end up have a lot of application
I have just begun working on a project which uses Mercurial as a version
I have started working on a project which requires Natural Language Processing. We have
I have a project which I am working on and it has multiple files
I have a project which I am working on and it has multiple files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.