Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Limiting Review Preview


alexallied

Recommended Posts

Posted

I need to limit my reviews on my product_info.php to around 3 or 5, how do I code that? I know a lil bit of PHP, not sufficient though to do this myself, I did extensive mod on oscommerce but this one got me.

 

Take a look at this...

Product Info Review

 

How do I limit the reviews summary to 3 and stop them from overflowing (if I ever had 100+ reviews, though that would be impossible :o )

 

Any help would be appreciated,

 

here's the code.

 

<?php
/*
 $Id: product_info.php,v 1.97 2003/07/01 14:34:54 hpdl Exp $

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

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 require('includes/application_top.php');

 $product_info_query = tep_db_query("select p.products_id, p.products_model, p.products_image, p.products_price, p.products_tax_class_id, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '" . (int)$languages_id . "'");
 if (!tep_db_num_rows($product_info_query)) {
   tep_redirect(tep_href_link(FILENAME_REVIEWS));
 } else {
   $product_info = tep_db_fetch_array($product_info_query);
 }

 if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
   $products_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
 } else {
   $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));
 }

 if (tep_not_null($product_info['products_model'])) {
   $products_name = $product_info['products_name'] . ' <span class="smallText">[' . $product_info['products_model'] . ']</span>';
 } else {
   $products_name = $product_info['products_name'];
 }

 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_REVIEWS);
 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_INFO);

 $product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
 $product_check = tep_db_fetch_array($product_check_query);
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<script language="javascript"><!--
function popupWindow(url) {
 window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,res
izable=yes,copyhistory=no,width=400,height=300,screenX=150,screenY=150,top=50,lef
t=50')
}
//--></script>
</head>
<body>
<div id="wrap"> 
 <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
 <div id="main"> 
   <table border="0" width="780" cellspacing="0" cellpadding="0" align="center">
     <tr> 
       <td><img src="images/pixel_trans.gif" border="0" width="1" height="<?php echo div_height; ?>"></td>
     </tr>
     <tr> 
       <td width="<?php echo BOX_WIDTH; ?>" valign="top"><img src="images/pixel_trans.gif" border="0" alt="" width="1" height="12"> 
         <table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="6" cellpadding="2">
           <?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
         </table></td>
       <!-- body_text //-->
       <td width="<?php echo MAIN_WIDTH; ?>" valign="top" height="100%"><?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')); ?> 
         <table border="0" width="100%" cellspacing="0" cellpadding="0">
           <?php
 if ($product_check['total'] < 1) {
?>
           <tr> 
             <td> 
               <?php new infoBox(array(array('text' => TEXT_PRODUCT_NOT_FOUND))); ?>
             </td>
           </tr>
           <tr> 
             <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
           </tr>
           <tr> 
             <td><table border="0" width="98%" cellspacing="0" cellpadding="0" align="center" class="infoBox">
                 <tr class="infoBoxContents"> 
                   <td><table border="0" width="98%" cellspacing="0" cellpadding="0" align="center">
                       <tr> 
                         <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                         <td align="right"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
                         <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                       </tr>
                     </table></td>
                 </tr>
               </table></td>
           </tr>
           <?php
 } else {
   $product_info_query = tep_db_query("select p.products_weight, p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
   $product_info = tep_db_fetch_array($product_info_query);

   tep_db_query("update " . TABLE_PRODUCTS_DESCRIPTION . " set products_viewed = products_viewed+1 where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and language_id = '" . (int)$languages_id . "'");

   if ($new_price = tep_get_products_special_price($product_info['products_id'])) {
     $products_price = '<s>' . $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) . '</s> <span class="productSpecialPrice">' . $currencies->display_price($new_price, tep_get_tax_rate($product_info['products_tax_class_id'])) . '</span>';
   } else {
     $products_price = $currencies->display_price($product_info['products_price'], tep_get_tax_rate($product_info['products_tax_class_id']));
   }

   if (tep_not_null($product_info['products_model'])) {
     $products_name = $product_info['products_name'] . ' <font class="footer">[' . $product_info['products_model'] . ']</font>';
   } else {
     $products_name = $product_info['products_name'];
   }
?>
           <tr> 
             <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
                 <tr> 
                   <td class="pageHeading"><img src="images/pixel_trans.gif" width="28" height="18" align="absmiddle"><?php echo HEADING_TITLE; ?></td>
                 </tr>
               </table></td>
           </tr>
           <tr> 
             <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
           </tr>
           <tr> 
             <td class="main"> 
               <?php
   if (tep_not_null($product_info['products_image'])) {
?>
               <table border="0" cellspacing="2" cellpadding="2" width="98%" align="center">
                 <tr> 
                   <td width="70%" class="main" valign="top"> <table border="0" cellspacing="1" cellpadding="1" width="99%" align="center">
                       <tr> 
                         <td class="main" valign="top"><b>Product Name:</b></td>
                         <td class="main"><?php echo $products_name; ?></td>
                       </tr>
                       <tr> 
                         <td class="main"><b>Price:</b></td>
                         <td class="main"><?php echo $products_price; ?></td>
                       </tr>
                       <tr> 
                         <td class="main"><b>Weight:</b></td>
                         <td class="main"> 
                           <?php $product_info_list_weight_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " 	 where configuration_key='PRODUCT_INFO_LIST_WEIGHT'");
  	 $product_info_list_weight=tep_db_fetch_array($product_info_list_weight_query);
  	 if ($product_info_list_weight['configuration_value']==1) {
     echo $product_info['products_weight'] . ' ' . TEXT_WEIGHT_UNIT;	} ?>
                         </td>
                       <tr> 
                         <td class="main" valign="top"><b>Description:</b></td>
                         <td class="main"><?php echo stripslashes($product_info['products_description']); ?></td>
                       </tr>
                       <?php }	?>
                       <?php
  	 $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'");
  	 $products_attributes = tep_db_fetch_array($products_attributes_query);
  	 if ($products_attributes['total'] > 0) { ?>
                       <tr> 
                         <td class="main" colspan="2"><b><?php echo TEXT_PRODUCT_OPTIONS; ?></b></td>
                       </tr>
                       <?php
        $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_name");
        while ($products_options_name = tep_db_fetch_array($products_options_name_query)) {
       $products_options_array = array();
       $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'");
       while ($products_options = tep_db_fetch_array($products_options_query)) {
         $products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name']);
         if ($products_options['options_values_price'] != '0') {
      	 $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') ';
         }
       }
     
       if (isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) {
         $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']];
       } else {
         $selected_attribute = false;
       }
     ?>
                       <tr> 
                         <td class="main"><?php echo $products_options_name['products_options_name'] . ':'; ?></td>
                         <td class="main"><?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?></td>
                       </tr>
                       <?php } ?>
                       <?php }	?>
                     </table></td>
                   <td width="30%" class="smallText" align="center"> <script language="javascript"><!--
document.write('<?php echo '<a href="javascript:popupWindow(\\\'' . tep_href_link(FILENAME_POPUP_IMAGE, 'pID=' . $product_info['products_id']) . '\\\')">' . tep_image(DIR_WS_CATALOG_IMAGES . $product_info['products_image'], addslashes($product_info['products_name']), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5" class="prod"') . '<br>' . TEXT_CLICK_TO_ENLARGE . '</a>'; ?>');
//--></script> <noscript>
                     <?php echo '<a href="' . tep_href_link(DIR_WS_CATALOG_IMAGES . $product_info['products_image']) . '" target="_blank">' . tep_image(DIR_WS_CATALOG_IMAGES . $product_info['products_image'], $product_info['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5" class="prod"') . '<br>' . TEXT_CLICK_TO_ENLARGE . '</a>'; ?> 
                     </noscript> </td>
                 </tr>
                 <tr> 
                   <td colspan="2"><?php echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_image_submit('button_in_cart.gif', IMAGE_BUTTON_IN_CART); ?> 
                     <?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS_WRITE, tep_get_all_get_params()) . '">' . tep_image_button('button_write_review.gif', IMAGE_BUTTON_WRITE_REVIEW) . '</a>'; ?> 
                     <?php echo '<a href="' . tep_href_link(FILENAME_TELL_A_FRIEND, tep_get_all_get_params()) . '">' . tep_image_button('button_tell_a_friend.gif', IMAGE_BUTTON_TELL_A_FRIEND) . '</a>'; ?> 
                     <?php if (isset($HTTP_GET_VARS['products_id'])) {

   if (tep_session_is_registered('customer_id')) {
     $check_query = tep_db_query("select count(*) as count from " . TABLE_PRODUCTS_NOTIFICATIONS . " where products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and customers_id = '" . (int)$customer_id . "'");
     $check = tep_db_fetch_array($check_query);

     $notification_exists = (($check['count'] > 0) ? true : false);
   } else {
     $notification_exists = false;
   }

   if ($notification_exists == true) {
     echo '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=notify_remove', $request_type) . '">' . tep_image_button('button_remove_notifications.gif', TEXT_NOTIFY_OFF) . '</a>';
   } else {
     echo '<a href="' . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=notify', $request_type) . '">' . tep_image_button('button_on_notifications.gif', TEXT_NOTIFY_ON) . '</a>';
   }


} ?>
                   </td>
                 </tr>
                 <tr> 
                   <td align="center" colspan="2"><img src="img/divbar.gif"></td>
                 </tr>
                 <tr> 
                   <td colspan="2"> <table border="0" width="100%" cellspacing="1" cellpadding="1" align="center">
                       <tr> 
                         <td width="50%"><img src="img/icons/caption_reviews.gif"></td>
                         <td width="1" rowspan="2" valign="middle"><img src="images/w.gif" height="95%" width="1"></td>
                         <td><img src="img/icons/caption_custserv.gif"></td>
                       </tr>
                       <tr> 
                         <td> <table border="0" width="100%" cellspacing="1" cellpadding="1" align="center">
                             <?php
 $reviews_query_raw = "select r.reviews_id, left(rd.reviews_text, 100) as reviews_text, r.reviews_rating, r.date_added, r.customers_name from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd where r.products_id = '" . (int)$product_info['products_id'] . "' and r.reviews_id = rd.reviews_id and rd.languages_id = '" . (int)$languages_id . "' order by r.reviews_id desc";
 $reviews_split = new splitPageResults($reviews_query_raw, MAX_DISPLAY_NEW_REVIEWS);

 if ($reviews_split->number_of_rows > 0) {
   if ((PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3')) {
?>
                             <tr> 
                               <td><table border="0" width="100%" cellspacing="0" cellpadding="0" align="center">
                                   <tr> 
                                     <td class="smallText"><?php echo $reviews_split->display_count(TEXT_DISPLAY_NUMBER_OF_REVIEWS); ?></td>
                                     <td align="right" class="smallText"><?php echo TEXT_RESULT_PAGE . ' ' . $reviews_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info'))); ?></td>
                                   </tr>
                                 </table></td>
                             </tr>
                             <tr> 
                               <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
                             </tr>
                             <?php
   }

   $reviews_query = tep_db_query($reviews_split->sql_query);
   while ($reviews = tep_db_fetch_array($reviews_query)) {
?>
                             <tr> 
                               <td><table border="0" width="100%" cellspacing="1" cellpadding="1" align="center" class="productListing">
                                   <tr> 
                                     <td class="caption_main" colspan="3" height="20"> <?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS_INFO, 'products_id=' . $product_info['products_id'] . '&reviews_id=' . $reviews['reviews_id']) . '"><b>' . sprintf(TEXT_REVIEW_BY, tep_output_string_protected($reviews['customers_name'])) . '</b></a>'; ?></td>
                                   </tr>
                                   <tr> 
                                     <td width="5"><?php echo tep_draw_separator('pixel_trans.gif', '5', '1'); ?></td>
                                     <td valign="top" class="smallText"><?php echo tep_break_string(tep_output_string_protected($reviews['reviews_text']), 60, '-<br>') . ((strlen($reviews['reviews_text']) >= 100) ? '...' : '') . '<br><br>' . sprintf(TEXT_REVIEW_RATING, tep_image(DIR_WS_IMAGES . 'stars_' . $reviews['reviews_rating'] . '.gif', sprintf(TEXT_OF_5_STARS, $reviews['reviews_rating'])), sprintf(TEXT_OF_5_STARS, $reviews['reviews_rating'])); ?></td>
                                     <td width="5" align="right"><?php echo tep_draw_separator('pixel_trans.gif', '5', '1'); ?></td>
                                   </tr>
                                 </table></td>
                             </tr>
                             <tr> 
                               <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
                             </tr>
                             <?php
   }
?>
                             <?php
 } else {
?>
                             <tr> 
                               <td> 
                                 <?php new infoBox(array(array('text' => TEXT_NO_REVIEWS))); ?>
                               </td>
                             </tr>
                             <tr> 
                               <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
                             </tr>
                             <?php
 }

 if (($reviews_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3'))) {
?>
                             <tr> 
                               <td><table border="0" width="100%" cellspacing="0" cellpadding="0" align="center">
                                   <tr> 
                                     <td class="smallText" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_PRODUCT_REVIEWS, tep_get_all_get_params()) . '">' ?>read 
                                       all reviews...</a></td>
                                   </tr>
                                 </table></td>
                             </tr>
                             <tr> 
                               <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
                             </tr>
                             <?php
 }
?>
                           </table></td>
                         <td valign="top"><font class="smallText">Place an offline 
                           order by calling us at</font><br> <font class="caption_main" color="#003399"><b>085 
                           433333</b></font><br> <font class="smallText">(+60) 
                           for International callers.<br>
                           <br>
                           For enquiries, please use our <a href="<?php echo tep_href_link(FILENAME_CONTACT_US); ?>"><b>Contact</b></a> 
                           form.</font> </td>
                       </tr>
                     </table></td>
                 </tr>
               </table></td>
           </tr>
           <tr> 
             <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
           </tr>
           <?php
   if (tep_not_null($product_info['products_url'])) {
?>
           <tr> 
             <td class="main"><?php echo sprintf(TEXT_MORE_INFORMATION, tep_href_link(FILENAME_REDIRECT, 'action=url&goto=' . urlencode($product_info['products_url']), 'NONSSL', true, false)); ?></td>
           </tr>
           <tr> 
             <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
           </tr>
           <?php
   }

   if ($product_info['products_date_available'] > date('Y-m-d H:i:s')) {
?>
           <tr> 
             <td align="center" class="smallText"><?php echo sprintf(TEXT_DATE_AVAILABLE, tep_date_long($product_info['products_date_available'])); ?></td>
           </tr>
           <?php
   } else {
?>
           <tr> 
             <td align="center" class="smallText"><br> <br> <br> <?php echo sprintf(TEXT_DATE_ADDED, tep_date_long($product_info['products_date_added'])); ?></td>
           </tr>
           <?php
   }
?>
           <tr> 
             <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
           </tr>
           <tr> 
             <td> 
               <?php
   if ((USE_CACHE == 'true') && empty($SID)) {
     echo tep_cache_also_purchased(3600);
   } else {
     include(DIR_WS_MODULES . FILENAME_ALSO_PURCHASED_PRODUCTS);
   }
 }
?>
             </td>
           </tr>
         </table></form>
         </td>
       <!-- body_text_eof //-->
     </tr>
   </table>
   <!-- body_eof //-->
 </div>
 <!-- footer //-->
 <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
 <!-- footer_eof //-->
</div>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Archived

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

×
×
  • Create New...