Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Put multi small images for categories.


goldoi

Recommended Posts

Hello everyone,

I have added two fields in my table sql categories to add two more images 2&3.

My sql categories look like this, the admin part works wel, i can add pictures:

sqlo.png

 

categories.php:

 

<?

   if (isset($cPath) && strpos('_', $cPath)) {
// check to see if there are deeper categories within the current category
  $category_links = array_reverse($cPath_array);
  for($i=0, $n=sizeof($category_links); $i<$n; $i++) {
    $categories_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "'");
    $categories = tep_db_fetch_array($categories_query);
    if ($categories['total'] < 1) {
	  // do nothing, go through the loop
    } else {
	  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.categories_image_2, c.categories_image_3, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
	  break; // we've found the deepest category the customer is in
    }
  }
   } else {
  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.categories_image_2, c.categories_image_3, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$current_category_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
   }

......
// AND DISPLAY THEM USING
    <td class="pageHeading" align="right">
<?php
   if (tep_not_null($category['categories_image']) && (file_exists(DIR_WS_IMAGES . $category['categories_image'])) ) {
  echo tep_image(DIR_WS_IMAGES . $category['categories_image'], $category['categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT);
   }
?>
</td>
<td class="pageHeading" align="center">
<?php
   if (tep_not_null($category['categories_image']) && (file_exists(DIR_WS_IMAGES . $category['categories_image'])) ) {
  echo tep_image(DIR_WS_IMAGES . $category['categories_image_2'], $category['categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT);
   }
?>
</td>
<td class="pageHeading" align="left">
<?php
   if (tep_not_null($category['categories_image']) && (file_exists(DIR_WS_IMAGES . $category['categories_image'])) ) {
  echo tep_image(DIR_WS_IMAGES . $category['categories_image_3'], $category['categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT);
   }
?>
    </td>

 

The function which manage the pictures into :

 

<?  function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '') {
   if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
  return false;
   }

This works:

echo tep_image(DIR_WS_IMAGES . $category['categories_image'], $category['categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT);

This doesn't work, how to fix this ?

echo tep_image(DIR_WS_IMAGES . $category['categories_image_2'], $category['categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT);

 

Thx

 

Goldoi

Link to comment
Share on other sites

<?  
 if ($category_depth == 'nested') {
   $category_query = tep_db_query("select cd.categories_name, c.categories_image, c.categories_image_2, c.categories_image_3 from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.categories_id = '" . (int)$current_category_id . "' and cd.categories_id = '" . (int)$current_category_id . "' and cd.language_id = '" . (int)$languages_id . "'");
   $category = tep_db_fetch_array($category_query) or die('Erreur SQL !<br>'.$category_query.'<br>'.mysql_error());
?>

<h1><?php echo $category['categories_name']; ?></h1>

<div class="contentContainer">
 <div class="contentText">
   <table border="0" width="100%" cellspacing="0" cellpadding="2">
  <tr>
<?php
   if (isset($cPath) && strpos('_', $cPath)) {
// check to see if there are deeper categories within the current category
  $category_links = array_reverse($cPath_array);
  for($i=0, $n=sizeof($category_links); $i<$n; $i++) {
    $categories_query = tep_db_query("select count(*) as total from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "'");
    $categories = tep_db_fetch_array($categories_query);
    if ($categories['total'] < 1) {
	  // do nothing, go through the loop
    } else {
	  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.categories_image_2, c.categories_image_3, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$category_links[$i] . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
	  break; // we've found the deepest category the customer is in
    }
  }
   } else {
  $categories_query = tep_db_query("select c.categories_id, cd.categories_name, c.categories_image, c.categories_image_2, c.categories_image_3, c.parent_id from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where c.parent_id = '" . (int)$current_category_id . "' and c.categories_id = cd.categories_id and cd.language_id = '" . (int)$languages_id . "' order by sort_order, cd.categories_name");
   }

   $number_of_categories = tep_db_num_rows($categories_query);

   $rows = 0;
   while ($categories = tep_db_fetch_array($categories_query)) {
  $rows++;
  $cPath_new = tep_get_path($categories['categories_id']);
  $width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';
  echo '	    <td align="center" class="smallText" width="' . $width . '" valign="top"><a href="' . tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . tep_image(DIR_WS_IMAGES . $categories['categories_image'], $categories['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br />' . $categories['categories_name'] . '</a></td>' . "\n";
  if ((($rows / MAX_DISPLAY_CATEGORIES_PER_ROW) == floor($rows / MAX_DISPLAY_CATEGORIES_PER_ROW)) && ($rows != $number_of_categories)) {
    echo '	  </tr>' . "\n";
    echo '	  <tr>' . "\n";
  }
   }

 

The code that i give on my first post come from index.php not categories.php, i have made a mistake and we couldn't edit message. I have put here the full code that i'am using from index.php. Thx you.

Link to comment
Share on other sites

up!

I try to do this but it doesn't work!

<?	$sql = 'SELECT categories_image_2,categories_image_3 FROM categories';
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
if (tep_not_null($req['categories_image_2']) && (file_exists(DIR_WS_IMAGES . $req['categories_image_2'])) ) {
  echo tep_image(DIR_WS_IMAGES . $req['categories_image_2'], $category['categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT);
}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...