Requseting a impression based script

Discussion in 'PHP' started by Dreads, Mar 28, 2008.

  1. #1
    I was wondering if there are any free scripts that can display the number of times a banner is displayed and remove it after a certain number.

    Like if it has an admin panel and u can add like

    Impressions - Code
    1000 - <a href""><img src="http:"></a>

    idk something like that would be really nice ;D
     
    Dreads, Mar 28, 2008 IP
  2. blognol

    blognol Peon

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    There is no any free script for that, but we can make it. Whether you have database in the server ?
     
    blognol, Mar 29, 2008 IP
  3. Xtrm2Matt

    Xtrm2Matt Active Member

    Messages:
    129
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Presuming you log the stats in a MySQL database, you could do something like:

    
    <?php
    $results = mysql_query( "SELECT impressions FROM table WHERE whatever" );
    $results_query = mysql_num_rows( $results );
    $results_array = mysql_fetch_array( $results );
    
    if( $results_query < 1000 )
    {
    	echo "Impressions - Code";
    	echo "".$results_array["impressions"]." - <a href=\"http://www.Xtrm2Matt.com"\><img src=\"http://www.Xtrm2Matt.com/someimage.jpg\"></img></a>";
    } else {
    	// It has over 1000 impressions, so let's do nothing
    }
    ?>
    
    PHP:
    Now, the above would output one result only. You could change it to do a "while" loop:

    
    <?php
    $results = mysql_query( "SELECT impressions FROM table" );
    
    while( $row = mysql_fetch_array( $results ) )
    {
    	if( $row["impressions"] < 1000 )
    	{
    		echo "Impressions - Code";
    		echo "".$row["impressions"]." - <a href=\"http://www.Xtrm2Matt.com"\><img src=\"http://www.Xtrm2Matt.com/someimage.jpg\"></img></a>";
    	} else {
    		// It has over 1000 impressions, so let's do nothing
    	}
    }
    ?>
    
    PHP:
    This would select ALL results in the table, and output everything providing it has less than 1000 impressions.

    Hope that helps you :)

    (I only use MSSQL in PHP, so the mysql_query, mysql_num_rows and mysql_fetch_array are based on how MSSQL works. If they are wrong for MySQL, then it shouldn't be hard to fix)
     
    Xtrm2Matt, Mar 29, 2008 IP