Displaying Images in rows and columns..php

Discussion in 'Web Design & Programming' started by Waffle, Nov 27, 2005.

  1. Waffle

    Waffle Alpha Geek

    Likes Received:
    38
    Trophy Points:
    0
    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.
    ?>

    <table width="88" height="31" border="0" cellpadding="0" cellspacing="2">
    <tr>
    <td align="center">
    <?php echo "<a href=\"$url\" target=\"_blank\"><img src=\"$banner\"  width=\"88\" height=\"31\" border=\"0\">";?></td> //echos the $banner into the table, and assigns the matching  $url to it so when its clicked, it goes to their website.
    </tr>
    </table>

    <?php //back in to php to end the while..

    ?>
    any suggestions?

    Much obliged.
     
  2. Sniper

    Sniper Administrator Staff Member

    Likes Received:
    59
    Trophy Points:
    63
  3. Waffle

    Waffle Alpha Geek

    Likes Received:
    38
    Trophy Points:
    0
    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. :D
     
  4. Waffle

    Waffle Alpha Geek

    Likes Received:
    38
    Trophy Points:
    0
    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 
    "<table width=100%><tr>";

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

    echo 
    "<td width="round(100/$halfel) ."%><a href=\"$url\" target=\"_blank\"><img src=\"$banner\" width=\"88\" height=\"31\" border=\"0\"></td>";
    if (
    $i==$halfel) { echo "</tr><tr>"; }

    }

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

    ?>
    sounds like it should work...
     
  5. Waffle

    Waffle Alpha Geek

    Likes Received:
    38
    Trophy Points:
    0
    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
     
  6. Addis

    Addis The King

    Likes Received:
    91
    Trophy Points:
    48
    I was going to suggest that, just to know can you post the loop code here?
     
  7. Waffle

    Waffle Alpha Geek

    Likes Received:
    38
    Trophy Points:
    0
    PHP:
    $elcount count($el);
    $halfel round($elcount/2);

    echo 
    "<table width=100%><tr>";

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

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

    }

    echo 
    "</tr></table>";
    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.
     

Share This Page