HabboxWiki needs you!
Are you a Habbo buff? Or maybe a rare trader with a bunch of LTDs? Get involved with HabboxWiki to share your knowledge!
Join our team!
Whether you're raving for rares, excited for events or happy helping, there's something for you! Click here to apply
Need a helping hand?
Check out our guides for all things to help you make friends, make rooms, and make money!


Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Location
    Over there. ^_^
    Posts
    1,100
    Tokens
    0

    Latest Awards:

    Lightbulb Tutorial: Basic Affiliate System

    Ross has requested this tutorial to know how the affiliate system works on my site!

    Right, this tutorial will explain how to:
    Have a page which will show random affiliates a number of them of your choice
    Have a page which will count how many clicks each link recieves
    Have a page which will show all of the affiliates and how many clicks they recieve
    Have a page which will allow you to add affiliates to the current list ;

    Right first of all you will need to create the tables required in the mysql db, in phpmyadmin run this query in your db:

    Code:
    CREATE TABLE `affiliates` (
    `id` int(11) NOT NULL auto_increment,
    `url` varchar(255) NOT NULL default '',
    `imgurl` varchar(255) NOT NULL default '',
    `total` int(11) NOT NULL default '0',
    PRIMARY KEY (`id`),
    FULLTEXT KEY `url` (`url`)
    ) ;
    right now that you've got the table sorted you'll need to connect to the database! create a file called affconnect.php, add this code to the page

    PHP Code:
    <?php
    $username 
    ""//database username
    $password ""//database password
    $host "localhost"// database host (Usually localhost)
    $database ""// database name
    $connect mysql_connect($host,$username,$password) or die("Error connecting to Database! " mysql_error());
    mysql_select_db($database $connect) or die("Cannot select database! " mysql_error()); //attempts to connect to database
    ?>
    fill in your mysql details and save , right now to show random affiliates, create a page called affiliates.php and add this code to it

    PHP Code:
    <?php 
    include ("affconnect.php"); // Connects to the DB

    $random mysql_query("select * from affiliates ORDER BY RAND() LIMIT 0, 10");  // Queries the database 

    while($r=mysql_fetch_array($random)){ //while loop

    extract($r);

    echo 
    "<center><a href='count.php?id=$id' target='_blank'>"
    echo 
    "<img border='0' height='31' width='88' vspace='2' src='$imgurl'></a></center>"
    }
    ?>
    now configuring it, to change the amount of random affiliates to show change

    PHP Code:
    $random mysql_query("select * from affiliates ORDER BY RAND() LIMIT 0, YOUR NUMBER");  // Queries the database 
    the part which says YOUR NUMBER to the amount you would like to show, if you would like to change how the affiliates are layed out you must edit this:

    PHP Code:
    echo "<center><a href='count.php?id=$id' target='_blank'>"
    echo 
    "<img border='0' height='31' width='88' vspace='2' src='$imgurl'></a></center>"
    but you must not change the hyperlink location unless count.php is in another directory, and $imgurl must stay the same!
    Now showing all of the affiliates together, create a page called allaff.php and add this code to it:

    PHP Code:
    <?php 
    echo "<center><table width='100%' cellspacing='2' cellpadding='0'><tr>";
    include (
    "affconnect.php");
    $result mysql_query("SELECT * FROM affiliates ORDER BY total DESC"); 

    while (
    $row mysql_fetch_object($result)) { // while loop While you are connected to the database do this...

    echo "<td align='center' style='font-face: verdana; font-size: 9px;'><a href='count.php?id=".$row->id."' target='_blank'><img src='".$row->imgurl."' height='31' width='88' border='0' vspace='2'></a><br>Hits Out: ".$row->total."</td>"
    }
    echo 
    "</tr></table></center>"

    ?>
    this will order all of your affiliates by how many clicks it has recieved like this

    Most Click -------- Least clicks

    you can also edit the layout of how you want to display the affiliates by editing the echo parts. Now counting the clicks create a file called count.php and add this code to it:

    PHP Code:
    <?php
    include ("affconnect.php");
    $id $_GET['id']; //Gets the id from the browser, ie, count.php?id=2
    if (!is_numeric($id)) //if the id is NOT a number exits the script
    {
    exit;
    }
    mysql_query ("UPDATE affiliates SET total = total + 1 WHERE id = '$id'"); //makes a database query and updates the field named total with the previous total +1(for the click)
    $result mysql_query("SELECT * FROM affiliates WHERE id = '$id'"); //makes another query and selects all from the table affiliates where field id equals the variable id(which we defined as the GET function)
    $row mysql_fetch_object ($result);
    header("Location: " $row->url); //makes a redirect to the specified URL of the link found in the database.
    ?>
    This code for count.php is basically the same as the code for count.php in my download cms tutorial it actually came from here first though and i applied it to the download cms. Now create a page called addaff.php and add this code to it:

    PHP Code:
    <?php
    include('affconnect.php');//include the file that connects to the database
    if(!empty($imgurl)) {//if the title is not empty, than do this function
    $url addslashes($url);
    $imgurl addslashes($imgurl);
    $total addslashes($total);

    $sql "INSERT INTO affiliates (id, url, imgurl, total) VALUES ('NULL', '$url','$imgurl','$total')";//Insert all of your information into the mynews table in your database
    $query mysql_query($sql) or die('Cannot query the database.<br>' mysql_error());
    echo 
    "<center>Affiliate Added.</center>";
    } else {
    ?>
    <form name='news' method='post' action='addaff.php'>
    <p>Please fill out all of the following fields:</p>
    <table width='100%' border='0' cellpadding='0' cellspacing='0'>
    <tr>
    <td width='117'>Site URL*:  </td>
    <td width='577'>

    <input type='text' name='url' size='50'>

    </td>
    </tr>
    <tr>
    <td width='117'>Link URL (88x31 Button)*:</td>
    <td width='577'>
    <input name='imgurl' type='text' size='50'>
    </td>
    </tr>
    <tr>
    <td width='117'>Total Hits*:</td>
    <td width='577'>
    <input name='total' value='0' onFocus='this.blur()' type='text' size='50'>
    </td>
    </tr>
    </table><br>
    <input type='submit' name='Submit' value='Submit'>
    </form>
    <?php
    }
    ?>
    this code is just a basic form script which will insert the data you add to the form into your mysql database, the total hits input has been locked so 0 hits will be what the affiliate starts off with.

    These are the codes i am currently using on xenigma.co.uk except i have password protected the add page, i will write a tutorial on doing this soon!, any problems with these codes PM me!

    Coming soon...
    Editing Affiliates
    Deleting Affiliates
    Password protecting the add page

    For more tutorials including this one check out xenigma.co.uk, this tutorial will also be stickied in my sub-forum
    Last edited by xEnigmA; 08-08-2005 at 07:29 PM.
    *Image Removed


    Ahemm.. How exactly was my sig innapropriate?
    Goddamit i hate this forum :@
    I RESIGN FROM GRAPHICS DESIGNER :@ :@ :@

  2. #2
    Join Date
    Nov 2004
    Location
    Daventry, Northants
    Posts
    1,510
    Tokens
    0

    Latest Awards:

    Default

    Damn, Great tut man

  3. #3
    Join Date
    Aug 2004
    Location
    Over there. ^_^
    Posts
    1,100
    Tokens
    0

    Latest Awards:

    Default

    before that post you just did you had 1337 posts!! rofl
    *Image Removed


    Ahemm.. How exactly was my sig innapropriate?
    Goddamit i hate this forum :@
    I RESIGN FROM GRAPHICS DESIGNER :@ :@ :@

  4. #4
    Join Date
    Jul 2004
    Location
    Bournemouth. UK
    Posts
    3,638
    Tokens
    0

    Latest Awards:

    Default

    Another great tut Mike!
    Last edited by iRoss; 08-08-2005 at 09:20 PM.
    REMOVED

    Edited by jesus (Forum Super Moderator): Please do not have text in your signature which is over size 4.

Posting Permissions

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