سؤال

<?php

include 'dbconnect.php';

$query = mysql_query("SELECT * FROM champicons") or die("Error: " . mysql_error());

echo "<table border='10' width='100%' cellpadding='10' >"; 
echo "<tr>";  
while($row = mysql_fetch_array($query)) {
    $image = $row[2];
    echo "<td>";
    echo '<img src="data:image/png;base64,' . base64_encode($image) . '" />';   
    echo "<td>";  
}  
echo "</tr>";
echo "</table>";          


?>

What I'm trying to achieve is for 10 images to be put in 1 row before dropping a row below and making another 10 images appear, right now the more images I put into the database the wider and smaller the current row gets and I can't see all the images.

It's hard to get it to create a new row at 10 images as the images are called on a while loop.

هل كانت مفيدة؟

المحلول

Add a counter before the loop and if in the loop.

$i = 1;
while($row = mysql_fetch_array($query)) { 
    $image = $row[2];
    echo "<td>";
    echo '<img src="data:image/png;base64,' . base64_encode($image) . '" />';   
    echo "</td>";
    if($i++%10 == 0) echo '</tr><tr>';  
}  

نصائح أخرى

I think you just need to count your iteration and insert new row according

$i=1;
while($row = mysql_fetch_array($query)){
    $image = $row[2];
    echo "<td>";
    echo '<img src="data:image/png;base64,' . base64_encode($image) . '" />';   
    echo "</td>";  
    $i++;
    if($i==10){
        $i=1;
        echo "</tr><tr>";  
    }
}  

As side note your </td> wasn't closed correctly

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top