Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code Review: Working with IP, MySQL, Webstat... ???

    Well, im back to php and right now, just trying to do a custom stat for my web... i know that there are lots of logfile analyzers, but i'm just trying to make this one work... First, php executes this code very slow, second it dont insert the matching records and the country to the last database connection...

    thanks for any possible assistance here.


    PHP Code:
    <?php

    //---------------------------------------------------
    // Sample code to display Visitor Country information 
    // PHP 4 
    //---------------------------------------------------

    // Establishing a database connection
        
        
    $db=mysql_connect("localhost","user","password");
    mysql_select_db("hits",$db);
        
    $all_records "SELECT * from views WHERE date_visit='2004-05-13'";
        
    $recordset mysql_query($all_records,$db);
        
    $myrow mysql_fetch_array($recordset);
        

    do{ 
        
      
    $id $myrow['id'];
      
    $page $myrow['page'];
      
    $date_visit=$myrow['date_visit'];
      
    $time_visit=$myrow['time_visit'];
      
    $ip $myrow['ip'];
            
      
    mysql_select_db("country",$db);        

     
    // Query for getting visitor countrycode
            
     
    $country_query  "SELECT country_name FROM iptoc WHERE IP_FROM<=inet_aton('$ip') AND IP_TO>=inet_aton('$ip') ";

     
    // Executing above query
        
    $country_exec mysql_query($country_query);

     
    // Fetching the record set into an array
     
    $ccode_array=mysql_fetch_array($country_exec);

     
    // getting the country name from the array
        
    $country_name=$ccode_array['country_name'];

    //Insert the matching record to the database
       
    mysql_select_db("stats");                
       
    $sql2="INSERT INTO views (id,page,date_visit,time_visit,ip,country) VALUES ('$id','$page','$date_visit','$time_visit','$ip','$country')";
            
    $result=mysql_query($sql2);    

     } while (
    $myrow=mysql_fetch_array($recordset));


    ?>
    Last edited by firepages; 05-17-2004 at 09:00 PM. Reason: Unclear problems

  • #2
    New Coder
    Join Date
    Apr 2004
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    firstly may i suggest you put your php in the php tags, secondly i think but im not sure that your database name has to be quoted .. you did it like so

    PHP Code:


    $country_query 
    "SELECT country_name FROM iptoc WHERE IP_FROM<=inet_aton('$ip') AND IP_TO>=inet_aton('$ip') "
    where it should be

    PHP Code:

    $country_query 
    "SELECT country_name FROM 'iptoc' WHERE IP_FROM<=inet_aton('$ip') AND IP_TO>=inet_aton('$ip') "
    but im not sure.... good luck
    Last edited by aspdude2004; 05-17-2004 at 06:46 PM.
    ...not bad for a thirteen year old

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,095
    Thanks
    11
    Thanked 101 Times in 99 Posts
    best way to debug this stuff is to let MySQL help you , e.g.

    PHP Code:
    <?
    $country_exec 
    mysql_query($country_query) or die($country_query mysql_error() ) ;
    ?>
    that way you find out if your query even executed , if not you should get a reason why.

    + if you are using a resourse identifier you have to use use it.
    $country_exec = mysql_query($country_query,$db);
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    New Coder
    Join Date
    Apr 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. I figured out what's wrong.

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Also you need to read our posting guidelines section 2

    http://www.codingforums.com/postguide.htm
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #6
    New Coder
    Join Date
    Apr 2004
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, next time, i'll try to keep clear subjects...

    well.. i was trying to change it... but it did not reflect in the thread listings... i did intentionaly try to reply in this thread bcoz i was navigating the site, and have seen that spookster seems to keep replying by "read our posting guidelines as you are required..."

    it's good anyway, it reminded us to stay focus... and make this site worthed for those who are interested in web.

    anyway, sorry again Sir.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •