Jump to content

PHP Pagination display images in a table help


conan318

Recommended Posts

Ok the pagination part is all working fine.

but i thought id be able to create a heap variables inside the loop then display the images in a table. the only trouble is all variables are grabbing the same img. i need them to grab the 10 different records.

 

thanks

 

$sql = "SELECT * FROM mongrels_db.gallery ORDER BY id DESC LIMIT $offset, $rowsperpage ";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

// while there are rows to be fetched...
while ($list = mysql_fetch_array($result)) {

$img1=$list['img'];
$img2=$list['img'];
$img3=$list['img'];
$img4=$list['img'];
$img5=$list['img'];
$img6=$list['img'];
$img7=$list['img'];
$img8=$list['img'];
$img9=$list['img'];
$img10=$list['img'];

  // echo data
    
  
   } // end while
  echo "<table><tr>";
echo "<td>"."<img src='../gallery/".$img1 ."' width='100' height='100''> "."</td>";
  echo "<td>"."<img src='../gallery/".$img2 ."' width='100' height='100''> "."</td>";
  echo "<td>"."<img src='../gallery/".$img3 ."' width='100' height='100''> "."</td>";
   echo "<td>"."<img src='../gallery/".$img4 ."' width='100' height='100''> "."</td></tr>";
  echo "<tr><td>"."<img src='../gallery/".$img5 ."' width='100' height='100''> "."</td>";
  echo "<td>"."<img src='../gallery/".$img6 ."' width='100' height='100''> "."</td>";
   echo "<td>"."<img src='../gallery/".$img7 ."' width='100' height='100''> "."</td>";
  echo "<td>"."<img src='../gallery/".$img8 ."' width='100' height='100''> "."</td>";
  echo "<tr><td>"."<img src='../gallery/".$img9 ."' width='100' height='100''> "."</td>";
  echo "<td>"."<img src='../gallery/".$img10 ."' width='100' height='100''> "."</td></tr>";

that's defeating the purpose of the loop. Do this instead:

$sql = "SELECT * FROM mongrels_db.gallery ORDER BY id DESC LIMIT $offset, $rowsperpage ";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

echo "<table><tr>";
// while there are rows to be fetched...
while ($list = mysql_fetch_array($result)) {
  echo "<td>"."<img src='../gallery/".$list['img'] ."' width='100' height='100''> "."</td>";
} // end while

$sql = "SELECT * FROM mongrels_db.gallery ORDER BY id DESC LIMIT $offset, $rowsperpage ";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

echo "<table><tr>";

// while there are rows to be fetched...
while ($list = mysql_fetch_array($result)) {

$img=$list['img'];

  // echo data
     echo "<td>"."<img src='../gallery/".$img."' width='100' height='100''> "."</td>";
  
   } // end while
  echo "</tr><table>";

 

otherwise to display the data later would have to make them an array

 

masterace beat me, we were close

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.