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>";

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.