Jump to content

[SOLVED] mysql/php limiting display with images


krv

Recommended Posts

hello

I have an upload script that uploads a file to a directory on my site once the file is uploaded it saves the file name as a reference point in mysql also a category is added.

 

I am trying to show the images by category but am having trouble limiting to 3 cells per row while in a loop from mysql_result

 

example:

while($row=mysql_fetch_array($result){

 

echo "

<tr>

  <td><img src='images/$row[filename][1]></td>

  <td><img src='images/$row[filename][2]></td> 

  <td><img src='images/$row[filename][3]></td>         

</tr>

<tr>

  <td><img src='images/$row[filename][4]></td>

  <td><img src='images/$row[filename][5]></td> 

  <td><img src='images/$row[filename][6]></td>         

</tr>

}

and so on....

so i guess im stuck on creating and limiting an array and count rows per category.

 

Thanks

<?php

$sqlimg = "SELECT id,category FROM ht_img WHERE category='$_POST[cat]'";

$imgresult = mysql_query($sqlimg)or die(mysql_error());

?>

<table cellspacing="0" style="width: 100%;text-align: center;">

<?php

while ($row=mysql_fetch_array($imgresult)){

$img = $row['name'];

$tablerows = "

<tr>

<td $tddisplay><img src=\"img/$img\" class=\"appdata-img\" /> <br /><input type=\"radio\" name=\"template\" /></td>

                <td $tddisplay><img src=\"img/$img\" class=\"appdata-img\" /> <br /><input type=\"radio\" name=\"template\" /></td>

                <td $tddisplay><img src=\"img/$img\" class=\"appdata-img\" /> <br /><input type=\"radio\" name=\"template\" /></td>

</tr>";

echo $tablerows;

}

 

?>

</table>

  • 1 month later...

solution

   $number_of_thumbs_in_row = 3;
    $result = mysql_query("
   SELECT
     id,name,
   FROM img
");
    $nr = mysql_num_rows($result);
    if (empty($nr))
        $result_final = "\t<tr><td>No images found</td></tr>\n";
    else {
        while ($row = mysql_fetch_array($result)) {
            $result_array[] = "<img src=\"images/$row[name]\" border=\"0\" />";
        }
        mysql_free_result($result);
        $result_final = "<tr>\n";
        foreach ($result_array as $thumbnail_link) {
            if ($counter == $number_of_thumbs_in_row) {
                $counter = 1;
                $result_final .= "\n</tr>\n<tr>\n";
            } else
                $counter++;
            $result_final .= "\t<td class=\"appdata-image-ol\">" . $thumbnail_link . "</td>\n";
        }
        if ($counter) {
            if ($number_of_photos_in_row - $counter)
                $result_final .= "\t<td colspan='" . ($number_of_photos_in_row - $counter) .
                    "'> </td>\n";
        }
        $result_final .= "</tr>";
    }
    echo $result_final;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.