1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Foreach Date Range Data As Json Code

Discussion in 'Programming' started by OH Pavel, May 23, 2017.

  1. #1
    Sir I Need Help On This Issue

    I Have Php Code And Have Data According Date Range. I Want Put My
    
        //Date Value
        //Clicks Value
        //Impression Value
        //Earnings Value
    
    
    PHP:
    On My Morris Graph Data



    My Php Code



    <?php
           $uid=dump_udata("id");
        $mstart = date('01/m/Y'); 
        $mend = date('d/m/Y');
        $dfrom = formget("from");
        $dto = formget("to");
        $sid = formget("id");
      
        if(empty($dfrom)){
        $dfrom=date('Y-m-d', strtotime('-7 days'));
        }
      
        if(empty($dto)){
        $dto=date('Y-m-d');
        }
      
        $msname = date('M j, Y', strtotime($dfrom));
        $mename = date('M j, Y', strtotime($dto));
        $start = new \DateTime(''.$dto.'');
        $end = new \DateTime(''.$dfrom.'');
        $diff = $end->diff($start);
        $interval = \DateInterval::createFromDateString('-1 day');
      
        $period = new \DatePeriod($start, $interval, $diff->days);
      
      
        $period = new \DatePeriod($start, $interval, $diff->days);
        foreach ($period as $date) {
            $thisdate = $date->format('Y-m-d');
        //Date Value
      
        if(empty($sid)){
        $clicks=mysql_num_rows(mysql_query("SELECT * FROM pvl_clicks WHERE userid='$uid' AND time='$thisdate' AND status='VALID'"));
        //Click Value
      
        $imp=mysql_num_rows(mysql_query("SELECT * FROM pvl_imp WHERE userid='$uid' AND time='$thisdate' AND status='VALID'"));
        //Impression Value
      
        $cpmearnp=mysql_fetch_array(mysql_query("SELECT *,SUM(earn) as earn FROM pvl_imp WHERE userid='$uid' AND time='$thisdate' AND status='VALID'"));
        $cpcearnp=mysql_fetch_array(mysql_query("SELECT *,SUM(earn) as earn FROM pvl_clicks WHERE userid='$uid' AND time='$thisdate' AND status='VALID'"));
        $cpmearn=$cpmearnp["earn"];
        $cpcearn=$cpcearnp["earn"];
        } else {
      
        $clicks=mysql_num_rows(mysql_query("SELECT * FROM pvl_clicks WHERE userid='$uid' AND time='$thisdate' AND status='VALID' AND siteid='$sid'"));
        //Click Value
      
        $imp=mysql_num_rows(mysql_query("SELECT * FROM pvl_imp WHERE userid='$uid' AND time='$thisdate' AND status='VALID' AND siteid='$sid'"));
        //Impression Value
      
        $cpmearnp=mysql_fetch_array(mysql_query("SELECT *,SUM(earn) as earn FROM pvl_imp WHERE userid='$uid' AND time='$thisdate' AND status='VALID' AND siteid='$sid'"));
        $cpmearn=$cpmearnp["earn"];
        $cpcearnp=mysql_fetch_array(mysql_query("SELECT *,SUM(earn) as earn FROM pvl_clicks WHERE userid='$uid' AND time='$thisdate' AND status='VALID' AND siteid='$sid'"));
        $cpcearn=$cpcearnp["earn"];
        }
      
        if(empty($cpmearn)){
        $cpmearn=0;
        }
        if(empty($cpcearn)){
        $cpcearn=0;
        }
      
        $revenue=($cpcearn+$cpmearn);
        //Earning Value
      
      
        }
        ?>
    PHP:

    My Morris Graph





    <script type="text/javascript">
        var Script = function () {
      
            //morris chart
      
            $(function () {
              // data stolen from http://howmanyleft.co.uk/vehicle/jaguar_'e'_type
        
      
        Morris.Area({
          element: 'hero-area',
          data: [{"y":"Date Value","click":"Click Value","impression":"Impression Value","earning":"Earnings Value"},{"y":"Date Value","click":"Click Value","impression":"Impression Value","earning":"Earnings Value"}],
          xkey: 'y',
          ykeys: ['click', 'impression', 'earning'],
          labels: ['clicks', 'impressions', 'earning']
        });
      
      
              $('.code-example').each(function (index, el) {
                eval($(el).text());
              });
            });
      
        }();
      
      
        </script>
    PHP:

    any guys can complete the moris chart data with my php value

    Is There Anyone Who Can Help Me Sir
     
    Last edited: May 23, 2017
    OH Pavel, May 23, 2017 IP
  2. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #2
    Frankly speaking, I don't think anyone will offer help when you ask "can someone please do this for me?"
    If you have a doubt in specific area or found a bug which you are trying to figure out for hours, ask here. You will get help in no time! Otherwise, you will not!

    That being said, try to go through the basic example of the charts: http://jsbin.com/uqawig/441/embed?js,output
    You can find lot more details in here: https://morrisjs.github.io/morris.js/lines.html

    Go through it, and try to implement it using the data you fetched from your database! And if you get into any trouble, ask here. But be specific! :)

    And one more thing, if I were you, I wouldn't use those depreciated mysql_*() functions. It will land you in trouble.
    Use mysqli or PDO to interact with the database.

    Hope this helps!
     
    akhileshbc, May 26, 2017 IP