Getting data to move to next line automatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Beginnera
    New Member
    • Jun 2009
    • 1

    #1

    Getting data to move to next line automatically

    I have never used php before however managed to install the script and setup the database tables for an open source script. So please excuse my lack of jargon.

    Currently a list of text ads that our output, and it can show all (which I want), however this means that it could potentially list 100 adds horizontally, without moving to the next line after X ads r X pixels.

    Example at: http://www.beneficialads.com/adview....00&direction=h

    How can I get it to move to the next line after X ads or X pixels, or some way so it doesn't just keep on going horizontally?

    Thanks in advance - if anyone can help :-S

    Code for that section is below:

    Code:
    function displayAds ($dbDatabase, $adsNum, $adsDirection, $adsWidth, $adsHeight)
        {
        $adsNum = (int) $adsNum;
        $adsDirection = substr($adsDirection, 0, 1);
        $adsWidth = (int) $adsWidth;
        $adsHeight = (int) $adsHeight;
    
        if ($adsNum>5)
        	{
            $adsNum = 1000000;
            } // For safety
    
        $clickURL = "http://".$_SERVER["HTTP_HOST"].str_replace("adview","adclick",$_SERVER["SCRIPT_NAME"]);
    
        echo "<script> function tpadstat(id) { var tpadImg = new Image(); tpadImg.src =('".$clickURL."?id='+id) } </script>";
    
        // Read ads
    
        $sql =  "SELECT id,title,line1,line2,hyperlink FROM ".$dbDatabase.".tpad_ads ".
                "WHERE deleted=0 ".
                "AND (expires>=now() OR expires IS NULL) ".
                "AND (clicks<maxclicks OR maxclicks IS NULL) ".
                "AND (views<maxviews OR maxviews IS NULL) ".
                "ORDER BY rand() ".
                "LIMIT ".$adsNum;
    
        echo "<table cellspacing=0 cellpadding=2 width=$adsWidth height=$adsHeight>";
        if ($adsDirection=="H")
            {
            echo "<tr>";
            }
    
        $result = mysql_query ($sql);
        while (list ($_id, $_title, $_line1, $_line2, $_hyperlink) = mysql_fetch_array($result))
            {
            // Display ad
    
            echo ($adsDirection=="V") ? "<tr><td nowrap>" : "<td nowrap>";
            echo parseAd ($_id, $_title, $_line1, $_line2, $_hyperlink);
            echo ($adsDirection=="V") ? "</td></tr>" : "</td>";
    
            // Write stats
    
            $sql = "UPDATE ".$dbDatabase.".tpad_ads SET views=views+1 WHERE id='".$_id."'";
            @mysql_query ($sql);
    
            $sql = "INSERT INTO ".$dbDatabase.".tpad_stats SET ad='".$_id."',date=now()";
            @mysql_query ($sql);
    
            $sql = "UPDATE ".$dbDatabase.".tpad_stats SET views=views+1 WHERE ad='".$_id."' AND date=now()";
            @mysql_query ($sql);
            }
    
        if ($adsDirection=="H")
            {
            echo "</tr>";
            }
    
        echo "<tr><td colspan=10 align=right><a href=\"adnew.php\" target=_blank>";
        echo "<font style=\"font-size: 7pt\">Your Beneficial Ad here?</font></a></td></tr>";
        echo "</table>";
        }
    
    if ($_GET["num"])
    	{
        $adsNum = $_GET["num"];
        }
    
    if ($_GET["direction"])
    	{
        $adsDirection = $_GET["direction"];
        }
    
    if ($_GET["width"])
    	{
        $adsWidth = $_GET["width"];
        }
    
    if ($_GET["height"])
    	{
        $adsHeight = $_GET["height"];
    	}
    
    displayAds ($dbDatabase, $adsNum, $adsDirection, $adsWidth, $adsHeight);
    
    ?>
    Last edited by Markus; Jun 7 '09, 07:33 PM. Reason: Added [code] tags.
  • prabirchoudhury
    New Member
    • May 2009
    • 162

    #2
    Getting data to move to next line automatically

    1. you need to break the row after a particular time you want.
    2. so for that you need to make a new table <tr>
    3. use modulus to know where you want to break the row


    Code:
    <?php 
      $total_ads = 100 ; // geting form database total fetch 
      ?>
      <table align=center border=0 >
       <tbody>
       	<TR><td>Header1</td><td>Header2</td><td>Header3</td><td>Header4</td><td>Header5</td>
       		 
        </TR>
      
       	<?
       	// run a for loop to generate the table body content
       for ($i=1; $i<= $total_ads; $i++)
    	 {
    	 	echo('<TD align=top>');
    	 	// print your add here
    	 	echo "ad-num".$i;
    	 	
    	 	echo('</TD>');
    	 	/*
    	 	 Now want to get 5 ads in one row. 
         use the Modulus to get the new row and here it is making new <tr> for the table 
    	 	*/
    	 	if($i % 5 == 0)
            {
            	// when it is fifth adds then close previous <tr> and open a new one
              echo '</tr>
              <tr>';
            }   
       }   
      ?>
      </TBODY>
    </TABLE>
    :)

    Comment

    Working...