Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Need help with categories_name sql query


bowen

Recommended Posts

Hi,

 

I need some help if poss...

 

Contrib missing_pics_2.1

 

I am using a contrib to hide categories from public view as i have lots of products in there that i do not wish to show live yet, which some are also because of missing images.

 

to make sure the products with missing images are in the right category i wanted to add a column into the missing_pics.php file, which i have done, but am having a problem with the sql query to pull the category name and place it next to the product...

 

I have added

$product_query3 = tep_db_query("SELECT categories_name FROM " . TABLE_CATEGORIES_DESCRIPTION . " WHERE categories_id='". $product2."'");
	$cat = tep_db_fetch_array($product_query3);

 

after:

$product_query2 = tep_db_query("SELECT categories_id FROM products_to_categories WHERE products_id = '" . (int)$id . "'");
       $product2 = tep_db_fetch_array($product_query2);

 

then added in

<td class="dataTableContent" align="center" width="30"><? echo $cat; ?></td>

 

after:

<tr>
                 <td class="dataTableContent" align="center" width="30"><? echo $id; ?></td>

 

But it doesnt show the category name at all... i have checked the sql query directly in phpmyadmin and it returns a result so i am pretty stumped... any help is appreaciated...

 

thanks - mark

Link to comment
Share on other sites

following is the full code for the missing_pics.php file

 

<?
/*
 missing_pics.php,v 2.1 2006/11/20 22:05:52

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Idea by FaustinoInc.com

 Rewritten by Brian Burton (dynamoeffects)

 Released under the GNU General Public License
*/
 require('includes/application_top.php');
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <? echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<? echo CHARSET; ?>">
<title><? echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<!-- header //-->
<? require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
 <tr>
   <td width="<? echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<? echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<? require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
   </table></td>
<!-- body_text //-->
   <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
     <tr>
       <td class="pageHeading"><? echo HEADING_TITLE; ?></td>
     </tr>
<?
 /* ------------------------------------------------------------- */
 /* ------------------ CONFIGURABLE SETTINGS -------------------- */
 /* ------------------------------------------------------------- */

 //Change this line if you keep your images stored in a strange directory.
 //Don't touch it unless you're having problems.
 $image_directory = DIR_FS_CATALOG . DIR_WS_IMAGES;


 /*  ** Image Columns **
  *  If you have various image contributions installed and have more than one  
  *  image column in your database, add additional items to this array to include them.
  *  For example, if you have UltraPics installed, the array would look like this:
  *  $image_columns = array('products_image',
  *                         'products_image_med', 	
  *                         'products_image_lrg', 	
  *                         'products_image_sm_1', 	
  *                         'products_image_xl_1', 	
  *                         'products_image_sm_2', 	
  *                         'products_image_xl_2', 	
  *                         'products_image_sm_3', 	
  *                         'products_image_xl_3', 	
  *                         'products_image_sm_4', 	
  *                         'products_image_xl_4', 	
  *                         'products_image_sm_5', 	
  *                         'products_image_xl_5', 	
  *                         'products_image_sm_6', 	
  *                         'products_image_xl_6');
  */
 $image_columns = array('products_image');

 /* ------------------ STOP EDITING HERE -------------------- */

 $column_query_string = '';
 $image_count = 0;

 foreach ($image_columns as $column) {
   if ($column_query_string != '') $column_query_string .= ', ';
   $column_query_string .= $column;
 }

 $image_array = array();
 $images_query = tep_db_query("SELECT products_id, " . $column_query_string . " FROM " . TABLE_PRODUCTS);

 while ($row = tep_db_fetch_array($images_query)) {
   $image_array[$row['products_id']] = array();

   foreach ($image_columns as $column) {
     if ($row[$column] != '') {
       $image_array[$row['products_id']][] = array('image' => $row[$column], 'column' => $column);
       $image_count++;
     }
   }
 }

 /* Our image array is now built, start checking files. */
 $missing_images = array();

 foreach ($image_array as $id => $product) {
   foreach ($product as $image) {
     if (!is_file($image_directory . $image['image'])) {
       if (!is_array($missing_images[$id])) $missing_images[$id] = array();

       $missing_images[$id][] = $image['image'] . '  <i>(Col: ' . $image['column'] . ')</i>';
     }
   }
 }
?>
     <tr>
       <td class="main">
<?  if (count($missing_images) > 0) { ?>
         <table border="0" width="100%" cellspacing="0" cellpadding="0">
           <tr>
             <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
               <tr class="dataTableHeadingRow">
                 <td class="dataTableHeadingContent" align="center" width="30"><?php echo TABLE_HEADING_PRODUCT_ID; ?></td>
                 <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_CATEGORY; ?></td>
                 <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCT_NAME; ?></td>
                 <td class="dataTableHeadingContent"><?php echo TABLE_HEADING_PRODUCT_IMAGES; ?></td>
               </tr>
<?
     foreach ($missing_images as $id => $files) { 
       $product_query = tep_db_query("SELECT products_name FROM products_description WHERE products_id = '" . (int)$id . "' AND language_id = '" . ($language_id > 0 ? (int)$language_id : '1') . "'");
       $product = tep_db_fetch_array($product_query);
       $product_query2 = tep_db_query("SELECT categories_id FROM products_to_categories WHERE products_id = '" . (int)$id . "'");
       $product2 = tep_db_fetch_array($product_query2);
	$product_query3 = tep_db_query("SELECT categories_name FROM " . TABLE_CATEGORIES_DESCRIPTION . " WHERE categories_id='". $product2."'");
	$cat = tep_db_fetch_array($product_query3);
?>
               <tr>
                 <td class="dataTableContent" align="center" width="30"><? echo $id; ?></td>
                 <td class="dataTableContent" align="center" width="30"><? echo $cat; ?></td>
                 <td class="dataTableContent"><a href="<? echo tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $product2[categories_id] . '&pID=' . $id . '&action=new_product') . '">' . $product['products_name']; ?></a></td>
                 <td class="dataTableContent">
<?     
       foreach ($files as $f) {
         echo $f . '<br />';
       }
?>
                 </td>
               </tr>
               <tr>
                 <td colspan="3" style="padding: 0px; height: 1px; font-size: 1px; background-color: #EFEFEF"></td>
               </tr>
<?
     }
?>
               </tr>
             </table></td>
           </tr>
         </table>
<?
   } else { ?>
         <table border="0" width="100%" height="100">
           <tr>
             <td class="main" valign="middle" align="center"><b><h2>Congratulations!</h2><br />You have <? echo $image_count . ' product image' . ($image_count == 1 ? '' : 's'); ?> in your store and they are all accounted for!</b></td>
           </tr>
         </table>
<?  } ?>
       </td>
     </tr>
   </table></td>

<!--    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php // require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- left_navigation_eof //-->
 <!--  </table></td> -->

<!-- body_text_eof //-->
 </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<? require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<? require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Link to comment
Share on other sites

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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