Array Condition

Discussion in 'PHP' started by sam20e, Feb 7, 2013.

  1. #1
    Hi

    I have a report.php page where when i click a link, the sql statement will be executed and results will be exported to csv file.

    To display the links (for example every monthly report)

    [Jan report]
    [Feb report]
    [Mar report]

    i use this code :

    $lst_csv = array(
    'List - Jan 2013'=>
    array(
    'table'=>'tbl_jan',
    'where'=>"WHERE v_id=12",
    'db'=>'main',
    'select'=>'name,id'),

    'List - Feb 2013'=>
    array(
    'table'=>'tbl_feb',
    'where'=>"WHERE v_id=12",
    'db'=>'main',
    'select'=>'name,id'),

    'List - Mar 2013'=>
    array(
    'table'=>'tbl_mar',
    'where'=>"WHERE v_id=12",
    'db'=>'main',
    'select'=>'name,id'),

    according to the current setup every month i need to add 1 portion for that month. Is there anyway i can add all 12 portion for all 12 months, but the array will display the link only if the current month is <= list month.

    Lets say i list down the link for all 12 months in 2013. If i run the php now, it should display link for Jan 2013 only.

    Any idea?

    Thanks
     
    sam20e, Feb 7, 2013 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    I'm not realy getting your point, you can work with date("m") to check current month and use if statement to check if you need to include that part of the array or not?
     
    EricBruggema, Feb 8, 2013 IP
  3. sam20e

    sam20e Member

    Messages:
    57
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #3
    how can i do that? ok this is what i want

    --------------
    Report.php
    --------------

    Output :

    Jan 2013
    Feb 2013
    Mar 2013
    Apr 2013
    May 2013
    June 2013
    July 2013
    Aug 2013
    Sep 2013
    Oct 2013
    Nov 2013
    Dec 2013

    --------------

    I need something like that as output, every month is a link, when i click a sql statement will be executed and csv file will be exported. now when im in Feb (actual month) the output page should only display Jan 2013.

    Lets say next month the out put should be Jan 2013 and Feb 2013 only... how can i set a if condition inside an array?

    Thanks
     
    sam20e, Feb 8, 2013 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    What not just run a cron job on the first of each month?
     
    MyVodaFone, Feb 8, 2013 IP