Displaying Images in rows and columns..php

Right, I’ve (somehow) coded a pretty nifty affiliates system for my site -

http://wafflesweb.co.uk/?module=resources&action=affiliates

Basically it allows the user to enter their website address, and the link to their banner, and its added to a database. These then get passed through some code, and are echoed back to the same page, as you can probably see if you visit that page.

However, I want it to echo them out in to rows and columns..ideally

5 affliates , then go down to the next row.

I’m sure this is possible.

Here is my code for showing the affiliate banners.

[php]

<?php $query="SELECT * from affiliates "; $result=mysql_query($query) or die ("Could not execute query: $q.". mysql_error()); while($row=mysql_fetch_array($result)) //gets all results in table { extract($row); // extract the row and values // leave php, html for formatting banners - this is the code that needs tweaking i think. ?> //echos the $banner into the table, and assigns the matching $url to it so when its clicked, it goes to their website.
<?php echo "";?>
<?php //back in to php to end the while.. } ?>

[/php]

any suggestions?

Much obliged.

I’ve not done this before so I suggest asking at www.sitepointforums.com

though maybe this can help?

http://www.bloodys.com/phpscripts.php at the end it has some sample code which might help you out, In 2 Rows and In 2 Columns.

btw: have you coded the whole site?

The private messenger was followed from a tutorial, and I had to read a user registration tut about ten times, but I think I nailed it now.

The affiliates system, the admin control and the “add news” was all coded by myself, and your help. :smiley:

Got some fast feedback on that site..I was told to create a counter, and put it in the loop, so when the counter = 5, it culls the row, starts a new one.

From the other site, the script I found, and my modified version:

[php]

<?php $query="SELECT * from affiliates "; $result=mysql_query($query) or die ("Could not execute query: $q.". mysql_error()); while($row=mysql_fetch_array($result)) { extract($row); $elcount = count($rowl); $halfel = round($elcount/2); echo ""; for ($i=1; $i<=$elcount; $i++) { echo ""; if ($i==$halfel) { echo ""; } } echo "
"; ?>

[/php]

sounds like it should work…

I’ve done it. code up there is full of errors and i havent uploaded the working version yet. will do tomorrow and post working code here

[QUOTE=Waffle]
I was told to create a counter, and put it in the loop, so when the counter = 5, it culls the row, starts a new one.

[/QUOTE]

I was going to suggest that, just to know can you post the loop code here?

[php]
$elcount = count($el);
$halfel = round($elcount/2);

echo “

”;

for ($i=1; $i<=$elcount; $i++) {

echo “<td width=”. round(100/$halfel) .“%>$el[$i]”;
if ($i==$halfel) { echo “

”; }

}

echo “

”;
[/php]

is the loop code..just taken from that script site.

I’ve discovered it only works with an array…and unless there is a way to put my list of affiliates into an array, I don’t believe it will work.