Hi there. Before i'm starting i want to say "sorry" for bad english. I'm only a 17 year old pupil from germany ;-)

ok, I have a mySQL Database and inside text with pictures-links like c:\pic\pic.jpg ... and i want to print them out, 3 pictures in a line, maybe in a table... I'm not completly sure if the post before mine is asking exactly this problem...
The Problem is: in the Database sometime i have only 2 entrys, or 10 entrys. So i need a code that fetch the rows AND the cols and show the pictures.

Can somebody help me, please ?

Here's the code i've just written:

<?php
   include("connect.php");

$query  = "SELECT

modellstamm.mods_artbez,

modellstamm.mods_inv_preis,

modellstamm.bgross,

modellstamm.bklein
FROM

modellstamm

WHERE

modellstamm.mods_schnitt='1070'";
$result = mysql_query($query,$db);
 if( !$result )
 {
    die("Falscher Datensatz !!!");
 }
 $nrows = mysql_num_rows($result);
 $row   = 0;
 $span1 = 50;
 $span2 = 20;
 while( $row < $nrows )
 {
$mods_artbez = mysql_result($result,$row,"mods_artbez");
$mods_inv_preis = mysql_result($result,$row,"mods_inv_preis");

$bklein = mysql_result($result,$row,"bklein");


?>
<a href="Picture-Test"
<img src="<?php echo $bklein; ?>" border=0 name="cart" alt="<?php echo $mods_artbez; ?>"></a>

<?php


     $row++;
 }
 mysql_free_result($result);
 mysql_close();
?>

SebHoff

    ehm .... sorry ...

    i've just mentioned, that the post before was the same problem .... now i can handle this !

    Thank you a lot !

    Sincerly, Sebhoff

    (ouu ... bad english ;-)

      You would be interested in using modulus.

      You say you want 3 columns, right? So you need to open a <tr> every 3 records after the first, and close it every 3 records after the third. So, let's use modulus.

      <?php
      echo "<table align=center>";
      $columnes = 3; # How many cols do you want?
      echo "<tr><td colspan=$columnes>$rows Results </td></tr>";
      if ($rows=0){echo "<tr><td colspan=$columnes>No results found.</td></tr> ";} 
      
      for ($i=1; $row = mysql_fetch_row ($result); $i++) {
      $resto = ($i % $columnes); # Number of the cell we are printing
      if ($resto == 1) {echo "<tr>";} # First of 3, open <tr>
          echo "<td>$row[1]</td>"; 
      if ($resto == 0) {echo "</tr>";} # Last of 3, close </tr>
      }
      if ($resto <> 0) { # Result not multiple of 3, let's fill blanks
      $ajust = $columnes - $resto; # Number of blank cells needed
      for ($j = 0; $j < $ajust; $j++) {echo "<td>&nbsp;</td>";}
      echo "</tr>" # We close the last </tr>
      }
      mysql_close($connexion);
      echo "</table>"; # That's all, folks
      ?>
        Write a Reply...