show images horizntally by extracting records from database?

  • asad_black
  • Graduate
  • Graduate
  • asad_black
  • Posts: 131
  • Loc: pakistan

Post 3+ Months Ago

this is my sample page ...!

http://tutioninn.com/wallpaper.php

in which images in a table show in a vertical direction but i want to show it horizontal way..!

like this page:
http://neosmart.net/gallery/v/wallpaper ... /Textures/

this is my code of selecting record...!

if u have better code from this code kindly reply me as soon as possible.

Code: [ Select ]


$sql = "SELECT * FROM wallpapers ;
$result = mysql_query($sql);

echo "<table border='1' cellpadding='3' cellspacing='3' width='60%'>";
echo "<tr>";

while ($list = mysql_fetch_assoc($result)) {

     {

echo "<td ><a href=\"idpage.php?id=" . $list["id"] . "\"><img src=\"" . $list["w_th"] . "\" ></a></td>";

echo "<td ><a href=\"idpage.php?id=" . $list["id"] . "\">". $list['w_name']. "</a>";
echo "</td>";

}
echo "</tr>";
}
  1. $sql = "SELECT * FROM wallpapers ;
  2. $result = mysql_query($sql);
  3. echo "<table border='1' cellpadding='3' cellspacing='3' width='60%'>";
  4. echo "<tr>";
  5. while ($list = mysql_fetch_assoc($result)) {
  6.      {
  7. echo "<td ><a href=\"idpage.php?id=" . $list["id"] . "\"><img src=\"" . $list["w_th"] . "\" ></a></td>";
  8. echo "<td ><a href=\"idpage.php?id=" . $list["id"] . "\">". $list['w_name']. "</a>";
  9. echo "</td>";
  10. }
  11. echo "</tr>";
  12. }
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • devilwood
  • Silver Member
  • Silver Member
  • User avatar
  • Posts: 436

Post 3+ Months Ago

Try this.

Code: [ Select ]

$sql = "SELECT * FROM wallpapers ;
$result = mysql_query($sql);

echo "<table border='1' cellpadding='3' cellspacing='3' width='60%'>";
echo "<tr>";

while ($list = mysql_fetch_assoc($result)) {

     { // not really sure what these brackets are for ,remove maybe

echo "<td ><a href=\"idpage.php?id=" . $list["id"] . "\"><img src=\"" . $list["w_th"] . "\" ></a></td>";

echo "<td ><a href=\"idpage.php?id=" . $list["id"] . "\">". $list['w_name']. "</a>";
echo "</td>";

} // you should be able to remove this one too


} // ends the while loop for all the table cells
echo "</tr></table>";
/* put ending tag after the while loop so all your <td> will be in one table row */
  1. $sql = "SELECT * FROM wallpapers ;
  2. $result = mysql_query($sql);
  3. echo "<table border='1' cellpadding='3' cellspacing='3' width='60%'>";
  4. echo "<tr>";
  5. while ($list = mysql_fetch_assoc($result)) {
  6.      { // not really sure what these brackets are for ,remove maybe
  7. echo "<td ><a href=\"idpage.php?id=" . $list["id"] . "\"><img src=\"" . $list["w_th"] . "\" ></a></td>";
  8. echo "<td ><a href=\"idpage.php?id=" . $list["id"] . "\">". $list['w_name']. "</a>";
  9. echo "</td>";
  10. } // you should be able to remove this one too
  11. } // ends the while loop for all the table cells
  12. echo "</tr></table>";
  13. /* put ending tag after the while loop so all your <td> will be in one table row */
  • devilwood
  • Silver Member
  • Silver Member
  • User avatar
  • Posts: 436

Post 3+ Months Ago

oops sorry didn't see your second link. You need to get a record count and then a little loop work to display however many images you want horizontally.

I'll dig you something up. I'll post again if someone doesn't beat me to it.

The current one will just put them all horizontally in one row. My mistake.
  • devilwood
  • Silver Member
  • Silver Member
  • User avatar
  • Posts: 436

Post 3+ Months Ago

Maybe Something like this. I actually have a file at home where I wrote this complete that handles the rounding of the last row better. Say the last row only has 2 images.


Code: [ Select ]

$sql = "SELECT * FROM wallpapers ;
$result = mysql_query($sql);

//set how many images to display horizontally
$pic_per_row = 4;

echo "<table border='1' cellpadding='3' cellspacing='3' width='60%'>";


$num = mysql_num_rows($result);

// number of table rows
$num_tr = ceil($num/$pic_per_row);


while ($list = mysql_fetch_assoc($result)) {

for ($i = 0; $i < $num_tr; $i++) {

echo "<tr>";     

for ($j = 0; $j < $pic_per_row; $j++) {
if ($list["id"] != "") { //handle the last row
echo "<td><a href=\"idpage.php?id=" . $list["id"] . "\"><img src=\"" . $list["w_th"] . "\" ></a></td>";

echo "<td ><a href=\"idpage.php?id=" . $list["id"] . "\">". $list['w_name']. "</a>";
echo "</td>";
} else {

echo "<td></td><td></td>";

}
        }

echo "</tr>";

    }

}
  1. $sql = "SELECT * FROM wallpapers ;
  2. $result = mysql_query($sql);
  3. //set how many images to display horizontally
  4. $pic_per_row = 4;
  5. echo "<table border='1' cellpadding='3' cellspacing='3' width='60%'>";
  6. $num = mysql_num_rows($result);
  7. // number of table rows
  8. $num_tr = ceil($num/$pic_per_row);
  9. while ($list = mysql_fetch_assoc($result)) {
  10. for ($i = 0; $i < $num_tr; $i++) {
  11. echo "<tr>";     
  12. for ($j = 0; $j < $pic_per_row; $j++) {
  13. if ($list["id"] != "") { //handle the last row
  14. echo "<td><a href=\"idpage.php?id=" . $list["id"] . "\"><img src=\"" . $list["w_th"] . "\" ></a></td>";
  15. echo "<td ><a href=\"idpage.php?id=" . $list["id"] . "\">". $list['w_name']. "</a>";
  16. echo "</td>";
  17. } else {
  18. echo "<td></td><td></td>";
  19. }
  20.         }
  21. echo "</tr>";
  22.     }
  23. }

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 126 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.