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.
Page 1 of 3 123 LastLast
Results 1 to 15 of 41
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    34 54' N 82 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Making a Linktracker

    What I am going to do is pass information through the HTTP Addess. I am using variables $des,$cat, and $link

    $des = name of site
    $link = address of site
    $cat = equals category of site

    I am wanting to see if field des has something that matches $des and if it does, add one to field hits

    If field des has nothing like $des, then enter the info and set it to one, where if clicked again, it will add one.

    Here is the code I have so far
    PHP Code:
    <?php

    $cat 
    $_GET['cat'];
    $des $_GET['des'];
    $link $_GET['link'];

    $conn mysql_connect("localhost","sdpeele","8590481");

    $db mysql_select_db("db");

    $result MYSQL_QUERY("SELECT * FROM linktracker WHERE des='$des'");

    $sql mysql_fetch_array($result);
    $des $sql['des'];

    if(
    $des){
        
    $result MYSQL_QUERY("UPDATE linktracker SET `hits`=`hits`+1 WHERE `des`='$des'");
    }
    elseif(!
    des){
        
    $result MYSQL_QUERY("INSERT INTO `linktracker`(`id`,`des`,`cat`,`href`,`hits`) VALUES('NULL','$cat','$des','$link','1')");
        
    }
    ?>
    Thanks for any help....
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #2
    New Coder
    Join Date
    Oct 2003
    Location
    AZ
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Making a Linktracker

    PHP Code:
    <?php

    $cat 
    $_GET['cat'];
    $des $_GET['des'];
    $link $_GET['link'];

    $conn mysql_connect("localhost","sdpeele","8590481");

    $db mysql_select_db("db");

    $result MYSQL_QUERY("SELECT * FROM linktracker WHERE des='$des'");

    $sql mysql_fetch_array($result);
    $resultsNum mysql_numrows($result# returns number of results

    # if resultsNum is greater or equal to 1
    if($resultsNum >= 1){
        
    $result MYSQL_QUERY("UPDATE linktracker SET `hits`=`hits`+1 WHERE `des`='$des'")or die(mysql_error)); # if query fails return error
    }
    else
    {
    # if resultsNum is not greater then or equal to 1 then it must be 0
        
    MYSQL_QUERY("INSERT INTO `linktracker`(`id`,`des`,`cat`,`href`,`hits`) VALUES('NULL','$cat','$des','$link','1')")or die(mysql_error)); # if query fails return error
        
    }
    ?>
    Last edited by coffeedemon; 01-26-2004 at 04:11 PM.
    PHP | FreeBSD | MySQL |
    Check documentation... check documentation again and actually read it..do it... doesn't work ask.

  • #3
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i don't have your answer but i would make another field called link_id and assign an id to the link so that
    when you do:
    $result = MYSQL_QUERY("SELECT * FROM linktracker WHERE des='$des'");

    it would be:
    $result = MYSQL_QUERY("SELECT * FROM linktracker WHERE link_id='$l_id'");


    matching numbers are the easiest and fastest, and using your method if and only if one char is diff it will be added into mysql...

    its just a sugesstion,
    fimi

  • #4
    Regular Coder
    Join Date
    May 2003
    Location
    34 54' N 82 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is my code, thanks to coffeedemon
    PHP Code:
    <?php

    $cat 
    $_GET['cat'];
    $des $_GET['des'];
    $link $_GET['link'];

    $conn mysql_connect("localhost","sdpeele","8590481");

    $db mysql_select_db("db",$conn);

    $result MYSQL_QUERY("SELECT * FROM linktracker WHERE des='$des'");

    $sql mysql_fetch_array($result);
    $resultsNum mysql_num_rows($result);

    if(
    $resultsNum >= 1){
        
    $result MYSQL_QUERY("UPDATE linktracker SET `hits`=`hits`+1 WHERE `des`='$des'") or die(mysql_error());
    }
    else
    {
        
    MYSQL_QUERY("INSERT INTO `linktracker`(`id`,`des`,`cat`,`href`,`hits`) VALUES('NULL','$cat','$des','$link','1')") or die(mysql_error());
        
    }
    ?>
    Now, it is inserting the proper data, but its not adding one to hits. Its creating the row over and over again not adding 1 to 'hits' if it is more than one. If you dont understand, see this - http://www.net-riches.com/pics/db.JPG -

    Thanks for all help...
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could just as well replace all this
    PHP Code:
    $result MYSQL_QUERY("SELECT * FROM linktracker WHERE des='$des'");

    $sql mysql_fetch_array($result);
    $resultsNum mysql_num_rows($result);

    if(
    $resultsNum >= 1){
        
    $result MYSQL_QUERY("UPDATE linktracker SET `hits`=`hits`+1 WHERE `des`='$des'") or die(mysql_error());
    }
    else
    {
        
    MYSQL_QUERY("INSERT INTO `linktracker`(`id`,`des`,`cat`,`href`,`hits`) VALUES('NULL','$cat','$des','$link','1')") or die(mysql_error());
        

    with
    PHP Code:
    $result mysql_query("REPLACE linktracker SET `hits`=(`hits`+1) WHERE `des`='" $des "'") or die(mysql_error()); 
    Replace will check if the record exists and update it or insert a new record. 'des' should then have a unique index or should be the primary key
    http://www.mysql.com/doc/en/REPLACE.html

  • #6
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by raf
    You could just as well replace all this
    PHP Code:
    $result MYSQL_QUERY("SELECT * FROM linktracker WHERE des='$des'");

    $sql mysql_fetch_array($result);
    $resultsNum mysql_num_rows($result);

    if(
    $resultsNum >= 1){
        
    $result MYSQL_QUERY("UPDATE linktracker SET `hits`=`hits`+1 WHERE `des`='$des'") or die(mysql_error());
    }
    else
    {
        
    MYSQL_QUERY("INSERT INTO `linktracker`(`id`,`des`,`cat`,`href`,`hits`) VALUES('NULL','$cat','$des','$link','1')") or die(mysql_error());
        

    with
    PHP Code:
    $result mysql_query("REPLACE linktracker SET `hits`=(`hits`+1) WHERE `des`='" $des "'") or die(mysql_error()); 
    Replace will check if the record exists and update it or insert a new record. 'des' should then have a unique index or should be the primary key
    http://www.mysql.com/doc/en/REPLACE.html
    LOL, i really like this.... i didn't know about REPLACE. 6 lines turned into 1
    thx for the tip
    Last edited by fimi; 01-26-2004 at 07:54 PM.

  • #7
    Regular Coder
    Join Date
    May 2003
    Location
    34 54' N 82 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In my table 'id' is my primary key.

    I'm kinda confused raf, can you show me the complete code and not just what to replace?

    Thanks
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #8
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $cat $_GET['cat'];
    $des $_GET['des']; // no need for this intermediate variable
    $link $_GET['link'];

    /*these should go inside an include. from here */
    $conn mysql_connect("localhost","sdpeele","8590481");

    $db mysql_select_db("db",$conn);
    /*to here */
    $result mysql_query("REPLACE linktracker SET `hits`=(`hits`+1) WHERE `des`='" $des "'") or die(mysql_error()); 
    You see, it could actualy be just 2 lines of code (one for the include and one for the query.)

    Now, replace need to know which record to look for to decide if it exists.
    If all values from 'des' are unique, then you can create a unique index on it. Or else you need to use the id (so the querystring should contain the id value then)
    Since each link can only point to one site, there shoukd be at least one 'no duplicate values' column inside your table. No ?

  • #9
    Regular Coder
    Join Date
    May 2003
    Location
    34 54' N 82 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Now, I'm really confuses.

    The replace function throws me for a loop.

    All I want to do is -> Check for matching value ($des), if matching value exists add one to 'hits' if matching value does not exist, then create the field.

    Errr, sorry if I am being a pain, buts thats kinda confusing.

    Thanks for the help...
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #10
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Not that I want to alarm anyone, but shouldn't we NOT give out our username and password???

  • #11
    Regular Coder
    Join Date
    May 2003
    Location
    34 54' N 82 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, but my host is pretty secure. You have to login into the control panel, then login to database management, and then login to phpmyadmin, (all three have different usernames and passwords)
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #12
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by SDP2006
    Now, I'm really confuses.

    The replace function throws me for a loop.
    How could that result in a loop? It will just execute the query once. If you get a loop, then it must be some othr code around the one you posted
    Originally posted by SDP2006
    All I want to do is -> Check for matching value ($des), if matching value exists add one to 'hits' if matching value does not exist, then create the field.
    Check the link in my previous post and you'll see it does exactly that.

    And bcarl314 is right about the user and pwd: All we need to do is take an account on the same host and we can manipulate your db. I don't see why we would need phpmyadmin.

  • #13
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by bcarl314
    Not that I want to alarm anyone, but shouldn't we NOT give out our username and password???
    test it in your server, see if you can use it :
    /*these should go inside an include. from here */
    $conn = mysql_connect("localhost","sdpeele","8590481");

    lol, that point is that it dosent matter, they do it on their own risk
    Last edited by fimi; 01-26-2004 at 08:59 PM.

  • #14
    Regular Coder
    Join Date
    May 2003
    Location
    34 54' N 82 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So....
    PHP Code:
    $cat $_GET['cat'];
    $des $_GET['des']; // no need for this intermediate variable
    $link $_GET['link'];

    /*these should go inside an include. from here */
    $conn mysql_connect("localhost","sdpeele","8590481");

    $db mysql_select_db("db",$conn);
    /*to here */
    $result mysql_query("REPLACE linktracker SET `hits`=(`hits`+1) WHERE `des`='" $des "'") or die(mysql_error()); 
    will do all i need it to do?
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #15
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    AND...

    Originally posted by raf
    Now, replace need to know which record to look for to decide if it exists.
    If all values from 'des' are unique, then you can create a unique index on it. Or else you need to use the id (so the querystring should contain the id value then)
    Since each link can only point to one site, there shoukd be at least one 'no duplicate values' column inside your table. No ?


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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