Jump to content

Insert ad code between records


s4salman

Recommended Posts

Hello Friends, i have this php code :

 

<?php

if (!ini_get("register_globals")) {
    import_request_variables('GPC');
}
//E?C?? ??I C?E? CEO E?
$phpver = phpversion();
if ($phpver < '4.1.0') {
    $_GET = $HTTP_GET_VARS;
    $_POST = $HTTP_POST_VARS;
    $_SERVER = $HTTP_SERVER_VARS;
}
$phpver = explode(".", $phpver);
$phpver = "$phpver[0]$phpver[1]";
if ($phpver >= 41) {
    $PHP_SELF = $_SERVER['PHP_SELF'];
}








class Pager
   {
       function getPagerData($numHits, $limit, $page)
       {
           $numHits  = (int) $numHits;
           $limit    = max((int) $limit, 1);
           $page     = (int) $page;
           $numPages = ceil($numHits / $limit);

           $page = max($page, 1);
           $page = min($page, $numPages);

           $offset = ($page - 1) * $limit;

           $ret = new stdClass;

           $ret->offset   = $offset;
           $ret->limit    = $limit;
           $ret->numPages = $numPages;
           $ret->page     = $page;

           return $ret;
       }
   } 



    // get the pager input values
    $page = $_GET['page'];
    $limit = 15;
    $result = mysql_query("select count(*) from funnyvideos");
    $total = mysql_result($result, 0, 0);

    // work out the pager values
    $pager  = Pager::getPagerData($total, $limit, $page);
    $offset = $pager->offset;
    $limit  = $pager->limit;
    $page   = $pager->page;

    // use pager values to fetch data
    $query = "select * from funnyvideos order by id DESC limit $offset, $limit";
    $result = mysql_query($query);

    // use $result here to output page content
//my addition

//grab all the content

   //Custom Table Stsrt//
        $cols = 5; //number of coloms
        $i =1;
        echo "<table border=\"1\" cellpadding=\"4\" cellspacing=\"4\" width=\"100%\" id=\"table1\" bgcolor=\"#e4e4e4\" class=\"breads\">"

             ."<tr>";

while($r=mysql_fetch_array($result))
{	
   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
  
   $id=$r["id"];
   $name=$r["name"];
   $details=$r["details"];
   $url=$r["url"];
   $picture=$r["picture"];
   
   
   //display the row
   
   
   
   $mybox = "$name
   <br>
   <a href='http://www.xy.com/funny-videos$id.html'><img src='http://www.xy.com/funnyvideos/images/$picture' width =\"100\" height =\"75\" border=\"1\" style=\"border: 1px double #000080\"></a>
   <br>
   <a href='http://www.xy.com/funny-videos$id.html'>$name</a>
   <br>";
   


                if (is_int($i / $cols)){
                    echo "<td width='200' align='center'>$mybox</td></tr><tr>";
                }else{
                    echo "<td width='200' align='center'>$mybox</td>";
                }
             $i++;
          //end if
       }//end while
       echo "</tr></table>";
      ?>

 

what i want is to insert two 468x60 size banner advertisement code below 1st and 2nd rown.One is the adsense ad code and the other is valueclickmedia banner code.

Please help me in this regard!

Link to comment
https://forums.phpfreaks.com/topic/133040-insert-ad-code-between-records/
Share on other sites

hey dude.

i'm not sure this is what you meant, but i assumed that by "below 1st and 2nd rows" you meant after those rows in the table you create in the loop at the bottom of the code.

 

so i changed the while() to a for(), and then check the row the loop is on with a switch inside the loop, with cases for after the 1st row, after the 2nd row, and all the rest. hope this is what you needed:

 

<?php 
//Custom Table Stsrt//
$cols = 5; //number of coloms
$i =1;
echo "<table border=\"1\" cellpadding=\"4\" cellspacing=\"4\" width=\"100%\" id=\"table1\" bgcolor=\"#e4e4e4\" class=\"breads\">"
."<tr>";

$loopCount = mysql_num_rows($result);
$loopCount += 2; //add 2 rows for the banners
        
for ($i = 0; $i < ($loopCount); ++$i){	

switch($i){
	case 1:
		//this is the value of $i after the first row was printed
		//put banner in a row here
		echo "</tr><tr>";
		break;
	case 3:
		//this is the value of $i after the second row was printed
		//put banner in a row here
		echo "</tr><tr>";
		break;
	default:
		//this just prints all the rows
		$r = mysql_fetch_array($result);
			//the format is $variable = $r["nameofmysqlcolumn"];
		//modify these to match your mysql table columns
  
		$id=$r["id"];
		$name=$r["name"];
		$details=$r["details"];
		$url=$r["url"];
		$picture=$r["picture"];
   
		//display the row
   
		$mybox = "$name
		<br>
		<a href='http://www.xy.com/funny-videos$id.html'><img src='http://www.xy.com/funnyvideos/images/$picture' width =\"100\" height =\"75\" border=\"1\" style=\"border: 1px double #000080\"></a>
		<br>
		<a href='http://www.xy.com/funny-videos$id.html'>$name</a>
		<br>";

		if (is_int($i / $cols)){
			echo "<td width='200' align='center'>$mybox</td></tr><tr>";
		}else{
			echo "<td width='200' align='center'>$mybox</td>";
		}//end if
                        break;
}//end switch
}//end for

echo "</tr></table>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.