[SOLVED] Affiliate Layout

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
sk8erh4x0r
Forum Commoner
Posts: 43
Joined: Wed May 26, 2004 8:27 pm

[SOLVED] Affiliate Layout

Post by sk8erh4x0r »

View here: http://hiddenskills.net/affiliates.php

I want the affiliate layout to be like this (periods used only to show spacing):

Affiliate button........Affiliate button........Affiliate button........Affiliate button
....(Hits: #).................. (Hits: #)..................(Hits: #)..................(Hits: #)

This is the code that gets the affiliate data and prints the buttons / hits.

Code: Select all

while($row = mysql_fetch_assoc($result))
{
echo "<a href=\"/out.php?id=".$row['id']."\" target=\"_blank\"><img src=\"".$row['button']."\" width=\"88\" height=\"31\" border=\"0\"></a><br><font size=\"2\">(Hits out: ".$row['hits'].")</font>";
}
If you go to the link above you can see that it returns after every affiliate button. What can I do to have 4 affiliates go across instead of carriage return after every affiliate?
Last edited by sk8erh4x0r on Wed Sep 14, 2005 5:43 pm, edited 1 time in total.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

move your output to several stages, output the basic link with your first call to echo, then when it comes time to decide wether or not to start a new line, use a conditional to check if the amount of loops you've made is divisible by 4 (hint: modulus %)


here's some psuedo code

Code: Select all

$count = count($array);
for($count=0;$count<$count; $count++) {
     // output some data
     echo ( $array[$count][0] );     

     if ($count % 4 == 0) {
            echo '<br />';
     }
     // output some data
     echo ( $array[$count][1] );     
}
sk8erh4x0r
Forum Commoner
Posts: 43
Joined: Wed May 26, 2004 8:27 pm

Post by sk8erh4x0r »

Code: Select all

<?php
$x = 1;
while($row = mysql_fetch_assoc($result))
{
echo "<a href=\"/out.php?id=".$row['id']."\" target=\"_blank\"><img src=\"".$row['button']."\" width=\"88\" height=\"31\" border=\"0\"></a><br><center><font size=\"2\">(Hits out: ".$row['hits'].")</center></font>";

$x = $x + 1;
if($x % 4 == 0){
echo "<br>";
}
}
?>
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

assuming your resultset has 2 fields

Code: Select all

<table>
<tr>
<?php
$x = 1;
while( list($test, $data) = mysql_fetch_array($result) ) {
	?>
	<td>
		<a href="<?=$test?>" target="_blank"><?=data?></a>  							
	</td>
	<?php
	
	$x++;
	if($x % 4 == 0){
		echo "</tr><tr>";
	}
}
?>
</tr>
</table>
that's the best I can do as far as psuedo code.
Post Reply