Author Topic: 2 each row, How to?  (Read 3553 times)

0 Members and 1 Guest are viewing this topic.

Offline webbug

  • Newbie
  • *
  • Posts: 33
    • View Profile
2 each row, How to?
« on: January 06, 2009, 11:05:38 AM »
I have the following code which list 4 images in each row.  I need to list 2 images per row please!

Code: [Select]
<?php
define
('ROOT_PATH''./');

include(
ROOT_PATH.'config.php');
$site_db = new Db($db_host$db_user$db_password$db_name);


$num_images 4;
$config['image_cells'] = 2;

$sql "SELECT a.image_id, a.cat_id, a.image_name, a.image_active, a.image_thumb_file, a.image_comments
        FROM "
.IMAGES_TABLE." a, ".CATEGORIES_TABLE." b
        WHERE a.image_active=1
        AND a.cat_id = b.cat_id
        AND b.auth_viewcat="
.AUTH_ALL."
        AND b.auth_viewimage="
.AUTH_ALL."
        ORDER BY a.image_id DESC
        LIMIT 
$num_images";
$result $site_db->query($sql);

while (
$row $site_db->fetch_array($result)){
  
$image_id $row['image_id'];
  
$cat_id $row['cat_id'];
  
$image_name $row['image_name'];
  
$image_comments $row['image_comments'];
  
$thumb_src = (is_remote($row['image_thumb_file'])) ? $row['image_thumb_file'] : ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'];
  echo 
"&nbsp;&nbsp;<a href=\"".ROOT_PATH."details.php?image_id=$image_id\"><img src=\"".$thumb_src."\" border=\"1\" alt=\"$image_name\"></a>&nbsp;&nbsp;";
  echo 
"<b>$image_name</b>\n";
  echo 
"Comments: $image_comments<hr>\n";
}
?>


Offline alekinna

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Gallery of cross-stitching
Re: 2 each row, How to?
« Reply #1 on: January 06, 2009, 11:34:05 AM »
Is it OK for you?

Code: [Select]
<?php
define
('ROOT_PATH''./');

include(
ROOT_PATH.'config.php');
$site_db = new Db($db_host$db_user$db_password$db_name);


$num_images 4;
$config['image_cells'] = 2;
$i 0;
$sql "SELECT a.image_id, a.cat_id, a.image_name, a.image_active, a.image_thumb_file, a.image_comments
        FROM "
.IMAGES_TABLE." a, ".CATEGORIES_TABLE." b
        WHERE a.image_active=1
        AND a.cat_id = b.cat_id
        AND b.auth_viewcat="
.AUTH_ALL."
        AND b.auth_viewimage="
.AUTH_ALL."
        ORDER BY a.image_id DESC
        LIMIT 
$num_images";
$result $site_db->query($sql);

while (
$row $site_db->fetch_array($result)){
  
$image_id $row['image_id'];
  
$cat_id $row['cat_id'];
  
$image_name $row['image_name'];
  
$image_comments $row['image_comments'];
  if(
$i == $config['image_cells']) {
    echo 
"<hr>";
  }
  
$thumb_src = (is_remote($row['image_thumb_file'])) ? $row['image_thumb_file'] : ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'];
  echo 
"&nbsp;&nbsp;<a href=\"".ROOT_PATH."details.php?image_id=$image_id\"><img src=\"".$thumb_src."\" border=\"1\" alt=\"$image_name\"></a>&nbsp;&nbsp;";
  echo 
"<b>$image_name</b>\n";
  echo 
"Comments: $image_comments\n";
  
$i++;
}
?>

Offline webbug

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: 2 each row, How to?
« Reply #2 on: January 06, 2009, 12:15:40 PM »
YEA!! Thanks alot  :D