Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Ordering Products


Guest

Recommended Posts

Posted

I am trying to order a set of random images (3 by 3) in a box on my main page. As of now it seems that one random image is being displayed but I can't make it work in 3 by 3 fashion. This is what I have so far -

 

<?php

 if ($random_product = tep_random_select("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status='1' limit " . MAX_RANDOM_SELECT_NEW)) {

   $random_product['products_name'] = tep_get_products_name($random_product['products_id']);

   $random_product['specials_new_products_price'] = tep_get_products_special_price($random_product['products_id']);



   $info_box_contents = array();

   $info_box_contents[] = array('align' => 'left',

                                'text'  => 'BOX_HEADING_MAIN_PRODUCTS'

                               );

   new infoBoxHeading($info_box_contents, true, false, tep_href_link(FILENAME_DEFAULT, '', 'NONSSL'));



   if ($random_product['specials_new_products_price']) {

     $rprod_price =  '<s>' . $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</s><br>';

     $rprod_price .= '<span class="productSpecialPrice">' . $currencies->display_price($random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</span>';

   } else {

     $rprod_price =  $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id']));

   }



   $row = 0;

   $col = 0;

   $info_box_contents = array();

   $info_box_contents[$row][$col] = array('align' => 'center',

                                   'text'  => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id'], 'NONSSL') . '">' . $random_product['products_name'] . '</a><br>' . $rprod_price);



   $col ++;

  if ($col > 2) {

     $col = 3;

     $row ++;

   }



   new infoBox($info_box_contents);

 }

?>

 

If any one knows how to fix this I would appreciate it.

 

Thanks,

Posted

To what is MAX_RANDOM_SELECT_NEW set?

 

Good luck,

Matt

Posted

I just took MAX_RANDOM_SELECT_NEW out from the code in order to get a true random image from the database however I need to create a while loop, something like this -

    $row = 0;

   $col = 0;

   $info_box_contents = array();

//  while () {

   $info_box_contents[] = array('align' => 'center',

                                'text'  => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id'], 'NONSSL') . '">' . $random_product['products_name'] . '</a><br>' . $rprod_price

                               );



//    $col ++;

//    if ($col > 2) {

//      $col = 0;

//      $row ++;

//    }

//  }



   new infoBox($info_box_contents);

 }

?>

 

Can you help me?

Posted

for ($row=0, $col=0, $info_box_contents = array(); $row < 3; ) {

   $info_box_contents[$row][$col] = array('align' => 'center',

                                   'text'  => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id'], 'NONSSL') . '">' . $random_product['products_name'] . '</a><br>' . $rprod_price);





   new infoBox($info_box_contents);

   $col ++;

   if ($col > 2) {

     $col = 0;

     $row ++;

   }

}

Hth,

Matt

 

P.S. MAX_RANDOM_SELECT_NEW does not make the results any less random. Btw, you still need to add code changing from product to product among those selected from the database. This code should print the same product nine times--let me know if it does that.

Posted

  $random_query = tep_db_query("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status='1' order by rand() limit 9");



 for ($row=0, $info_box_contents = array(); $row < 3;$row++ ) { 

  for ($col=0; $col < 3; $col++) {

   $random_product = tep_db_fetch_array($random_query);

   $random_product['products_name'] = tep_get_products_name($random_product['products_id']); 

   $random_product['specials_new_products_price'] = tep_get_products_special_price($random_product['products_id']); 



   $info_box_contents[$row][$col] = array('align' => 'center', 

                                       'text'  => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id'], 'NONSSL') . '">' . $random_product['products_name'] . '</a><br>' . $rprod_price); 

  }

 }

 new contentBoxHeading($info_box_contents);

I think that this should print 9 different items. It occurs to me that having the new statement inside the for loop was a mistake. I also simplified the logic by adding another loop.

 

Good luck,

Matt

Posted

<!-- show_random //-->

  <table border="0" cellspacing="0" cellpadding="0" width="100%">

         <tr>

           <td>

<?php



 if ($random_product = tep_random_select("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status='1'")) {

   $random_product['products_name'] = tep_get_products_name($random_product['products_id']);

   $random_product['specials_new_products_price'] = tep_get_products_special_price($random_product['products_id']);



   $info_box_contents = array();

   $info_box_contents[] = array('align' => 'left',

                                'text'  => 'BOX_HEADING_MAIN_PRODUCTS'

                               );

   new infoBoxHeading($info_box_contents, true, false, tep_href_link(FILENAME_DEFAULT, '', 'NONSSL'));



$random_query = tep_db_query("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status='1' order by rand() limit 9"); 



for ($row=0, $info_box_contents = array(); $row < 3;$row++ ) { 

for ($col=0; $col < 3; $col++) { 

$random_product = tep_db_fetch_array($random_query); 

$random_product['products_name'] = tep_get_products_name($random_product['products_id']); 

$random_product['specials_new_products_price'] = tep_get_products_special_price($random_product['products_id']); 



$info_box_contents[$row][$col] = array('align' => 'center', 

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id'], 'NONSSL') . '">' . $random_product['products_name'] . '</a><br>' . $rprod_price); 

} 

} 

new contentBoxHeading($info_box_contents); 



?>

           </td>

         </tr>

  </table>

<!-- show_random_eof //-->

 

it seems that it says that in line

$random_query = tep_db_query("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status='1' order by rand() limit 9");

it doesn't expect the '$' and when I take it out is doesn't like that = sign,

 

any ideas, and thanks so much for this help

Posted

Well, before I look into it, the first thought that comes to mind is to replace $random_query with $random_products_query everywhere it is used. I take it that that is line 50 of main_products.php?

 

Good luck,

Matt

Posted

I made the change but it still happens. Did I paste the code in the right spot?

Posted

After some off-forum correspondence, we ended up with this code:

<?php

 $info_box_contents = array();

 $info_box_contents[] = array('align' => 'left',

                                'text'  => 'BOX_HEADING_MAIN_PRODUCTS'

                               );

 new infoBoxHeading($info_box_contents, true, false, tep_href_link(FILENAME_DEFAULT, '', 'NONSSL'));





 $random_products_query = tep_db_query("select products_id, products_image, products_tax_class_id, products_price from " . TABLE_PRODUCTS . " where products_status='1' order by rand() limit 9"); 



 for ($row=0, $info_box_contents = array(); $row < 3;$row++ ) { 

   for ($col=0; $col < 3; $col++) { 

     $random_product = tep_db_fetch_array($random_products_query); 

     $random_product['products_name'] = tep_get_products_name($random_product['products_id']); 

     $random_product['specials_new_products_price'] = tep_get_products_special_price($random_product['products_id']); 



     $info_box_contents[$row][$col] = array('align' => 'center', 

'text' => '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $random_product['products_image'], $random_product['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $random_product['products_id'], 'NONSSL') . '">' . $random_product['products_name'] . '</a><br>' . $rprod_price); 

   } 

 }



 new contentBox($info_box_contents); 

?>

Archived

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

×
×
  • Create New...