Jump to content

timmah1

Members
  • Posts

    1,170
  • Joined

  • Last visited

Posts posted by timmah1

  1. I'm trying to get a bar graph from total number of hit on a month to month basis.

     

    Everything works out find, except the bar graph is only showing 1 month, not everything that's being pulled out of the db.

     

    Can anybody look and see what I'm doing wrong?

     

    $userid = '44';
    $t_month = date("Y-m-d h:i:s");
    $y_month = date("Y-m-d h:i:s", strtotime("-1 Year"));
    
    //Grabs Unique Visitors to App Page
    $query = "SELECT CONCAT_WS(' ', YEAR(date), MONTHNAME(date)) AS RptDate, COUNT(DISTINCT referrer) 'referrer' 
    FROM app_analytics 
    WHERE appid = $userid 
    AND date BETWEEN '" .$y_month."'  AND  '" .$t_month."' 
    GROUP BY CONCAT_WS(' ', YEAR(date), MONTHNAME(date))
    ORDER BY YEAR(date), MONTH(date)";
    
        $result = mysql_query($query) or die(mysql_error());        
            //$totals = array();
            while($row = mysql_fetch_array( $result )){
               
                $months = date("M", strtotime($row['RptDate']));
                $ip = $row['referrer'];  
                 
               $values = array("$months" => $ip);
          
        $img_width=450;
    $img_height=300; 
    $margins=20;
    
    
    # ---- Find the size of graph by substracting the size of borders
    $graph_width=$img_width - $margins * 2;
    $graph_height=$img_height - $margins * 2; 
    $img=imagecreate($img_width,$img_height);
    
    
    $bar_width=20;
    $total_bars=count($values);
    $gap= ($graph_width- $total_bars * $bar_width ) / ($total_bars +1);
    
    
    # -------  Define Colors ----------------
    $bar_color=imagecolorallocate($img,0,64,128);
    $background_color=imagecolorallocate($img,240,240,255);
    $border_color=imagecolorallocate($img,200,200,200);
    $line_color=imagecolorallocate($img,220,220,220);
    
    # ------ Create the border around the graph ------
    
    imagefilledrectangle($img,1,1,$img_width-2,$img_height-2,$border_color);
    imagefilledrectangle($img,$margins,$margins,$img_width-1-$margins,$img_height-1-$margins,$background_color);
    
    
    # ------- Max value is required to adjust the scale	-------
    $max_value=max($values);
    $ratio= $graph_height/$max_value;
    
    
    # -------- Create scale and draw horizontal lines  --------
    $horizontal_lines=20;
    $horizontal_gap=$graph_height/$horizontal_lines;
    
    for($i=1;$i<=$horizontal_lines;$i++){
    	$y=$img_height - $margins - $horizontal_gap * $i ;
    	imageline($img,$margins,$y,$img_width-$margins,$y,$line_color);
    	$v=intval($horizontal_gap * $i /$ratio);
    	imagestring($img,0,5,$y-5,$v,$bar_color);
    
    }
    
    
    # ----------- Draw the bars here ------
    for($i=0;$i< $total_bars; $i++){ 
    	# ------ Extract key and value pair from the current pointer position
    	list($key,$value)=each($values); 
    	$x1= $margins + $gap + $i * ($gap+$bar_width) ;
    	$x2= $x1 + $bar_width; 
    	$y1=$margins +$graph_height- intval($value * $ratio) ;
    	$y2=$img_height-$margins;
    	imagestring($img,0,$x1+3,$y1-10,$value,$bar_color);
    	imagestring($img,0,$x1+3,$img_height-15,$key,$bar_color);		
    	imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color);
    }
    
    header("Content-type:image/png");
    imagepng($img);
    }  
    

     

    Thanks in advance

  2. ok

     

    This is working except for 2 things

     

    It shows every month as December, and it don't give the total count?

     

    I'm not sure what I'm doing wrong

     

    Here is the code

    $userid = '49';
    $t_month = date("Y-m-d h:i:s");
    $y_month = date("Y-m-d h:i:s", strtotime("-1 Year"));
    
    //Grabs Unique Visitors to App Page
    $query = "SELECT MONTH(date), COUNT(DISTINCT referrer) 'referrer' FROM app_analytics WHERE appid = $userid AND date BETWEEN '" .$y_month."'  AND  '" .$t_month."' GROUP BY MONTH(date)";
    
        $result = mysql_query($query) or die(mysql_error());
    
            $hits = mysql_num_rows($result);
            
            while($row = mysql_fetch_array( $result )){
                
                $months = date("m", strtotime($row['date'])); 
                $ip = $row['referrer'];
    			echo $hits."<br />";
    			echo $months."-".$ip."<br />";
    
          }
    

  3. I'm trying to get a total number from the db where the month is the same and the ip is different.

    This is a stats script that someone else wrote, and I'm just trying to get a month-to-month total.

     

    Right now, it pulls the information out and displays the month with how many different ips came that month, the problem is, it lists like this:

     

    June - 41 - 41

     

    June - 1 - 1

     

    June - 1 - 1

     

    June - 1 - 1

     

    June - 1 - 1

     

    June - 1 - 1

     

    June - 9 - 9

     

    June - 2 - 2

     

    June - 2 - 2

     

    June - 2 - 2

     

    June - 1 - 1

     

    June - 3 - 3

     

    June - 2 - 2

     

    June - 4 - 4

     

    June - 1 - 1

     

    June - 13 - 13

     

    June - 154 - 154

     

    what I need to do is grab all those numbers and give a total for that month, in this case, June.

     

    This is my query

    $query = "SELECT date, COUNT(referrer)'referrer' FROM app_analytics WHERE appid = $userid AND date BETWEEN '" .$y_month . "' AND '" . $t_month . "' GROUP BY referrer ORDER BY date";
    

     

    Can anybody help out?

     

    Thanks in advance

  4. No matter what I try, I keep getting a session error.

     

    Can somebody look at this code and see what the problem?

     

    <?php
    ob_start();
    session_start();
    ini_set("display_errors",'ON');
    require_once('../lib/config.db.php');
    require_once('../inc/auth_func.php');
    $message = '';
    //echo DECRYPT('w9Ti2cqStdDU2w==');
    if (!empty($_POST)) {
    	$post = array();
    	foreach ($_POST as $key => $value) {
    		$post[$key] = mysql_real_escape_string(strip_tags(html_entity_decode($value)));
    	}
    
    	$username = $post['username'];
    	$password = ENCRYPT($post['password']);
    
    	$sql = sprintf("SELECT id, name,transactionid FROM app_logins WHERE username = '%s' AND password = '%s' AND active = 1", $username, $password);
    	$result = mysql_query($sql) or trigger_error(mysql_error());
    
    	if ($result && mysql_num_rows($result) > 0) {
    		$row = mysql_fetch_object($result);
    		$sqlapp = "SELECT * FROM app_queue WHERE transactionid={$row->transactionid} ORDER BY appid ASC LIMIT 1";
    		$rsapp = mysql_query($sqlapp);
    		if($rsapp && mysql_num_rows($rsapp) > 0){
    			$rowapp = mysql_fetch_object($rsapp);
    			$_SESSION['default_appid'] = $rowapp->appid;
    		}
    		$_SESSION['app_login_id'] = $row->id;
    		$_SESSION['login_name'] = $row->name;
    		$_SESSION['tid'] = $row->transactionid;
    		$location = !empty($post['from']) ? urldecode($post['from']) : 'index.php';
    		//ob_clean();	
    		header("location:{$location}");
    
    	} else {
    		$message =  '<p style="color:red;">That username and password<br />combination match none of our logins</p>';
    	}
    }
    ?>
    

     

    Thank you in advance

  5. I'm trying to make a map that will show your current location, but also load an xml file to show certain attractions in your area.

     

    Can anybody help me figure this out?

     

    I have the code to work for getting your current location, but I can't figure out how to implement loading the xml file and placing markers based off of that xml file.

     

    Here is the code for getting my location:

    <script>
    function initialize_map()
    {
        var myOptions = {
          zoom: 4,
          mapTypeControl: true,
          mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
          navigationControl: true,
          navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
          mapTypeId: google.maps.MapTypeId.ROADMAP      
        }	
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    }
    function initialize()
    {
    if(geo_position_js.init())
    {
    	document.getElementById('current').innerHTML="Receiving...";
    	geo_position_js.getCurrentPosition(show_position,function(){document.getElementById('current').innerHTML="Couldn't get location"},{enableHighAccuracy:true});
    }
    else
    {
    	document.getElementById('current').innerHTML="Functionality not available";
    }
    }
    
    function show_position(p)
    {
    document.getElementById('current').innerHTML="latitude="+p.coords.latitude.toFixed(2)+" longitude="+p.coords.longitude.toFixed(2);
    var pos=new google.maps.LatLng(p.coords.latitude,p.coords.longitude);
    map.setCenter(pos);
    map.setZoom(14);
    
    var infowindow = new google.maps.InfoWindow({
        content: "<strong>yes</strong>"
    });
    
    var marker = new google.maps.Marker({
        position: pos,
        map: map,
        title:"You are here"
    });
    
    google.maps.event.addListener(marker, 'click', function() {
      infowindow.open(map,marker);
    });
    
    }
    </script >
    

  6. Purely because I am curious why this wouldn't be working; if you want to PM me some credentials, I have some time to take a look personally.

     

    I appreciate that. Everything that I have is in this thread, the code, and screen shots of the db.

    If you're asking for credentials to log in to the db, that, I cannot do.

     

    Look, I understand about security ... etc - personally I don't care about what is in your database.

     

    Regardless, 'everything' that you have, that is posted here, obviously isn't working - so, you try something different. Maybe there is something that you think is irrelevant but is actually the reason it isn't working .... that's what I am getting at.

     

    The definition of insanity is doing the same thing, over and over, expecting different results each time.

     

    Hope it works out for you.

     

    Hey, I appreciate the offer, I really do, but look from my perspective, you say "personally I don't care about what is in your database", you're right, but a couple clicks, and the entire db is wiped out, I'm not saying you'd do that, but allowing someone access your db from a help forum, in my mind, is ludicrous.

     

    And you're right about the definition of insanity, hence, why I'm here. I've been trying multiple different ways to get this to work, with no luck

  7. Purely because I am curious why this wouldn't be working; if you want to PM me some credentials, I have some time to take a look personally.

     

    I appreciate that. Everything that I have is in this thread, the code, and screen shots of the db.

    If you're asking for credentials to log in to the db, that, I cannot do.

  8. Yeah, that's it. And now it makes even less sense, since everything there looks fine. As a last resort at diagnosing the problem, try this and see what it returns.

     

    <?php
    $query = "SELECT id_pk FROM page_listings ORDER BY id_pk DESC LIMIT 10";
    if( $result = mysql_query($query) ) {
         while($array = mysql_fetch_row($result) ) {
              echo $array[0] . '<br>';
         }
    } else {
         echo 'Error: ' . mysql_error();
    }
    

     

    This returns the following

    205950
    205949
    205948
    205947
    205946
    205945
    205944
    205943
    205942
    205941

  9. Ok, doing this

    $data = mysql_query("SELECT * FROM page_listings WHERE id_pk = 300000");
    while($result = mysql_fetch_array( $data ) or die("Error: ".mysql_error($data)))
    

    produces the word Error:, nothing else

     

    If I take the id_pk below the one in the picture, 200110, and hard-code that in, it pulls the info.

    I can pull info for every record in the db, expect the one I manually inserted

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.