Need some help with PHP And MySQL to show 2 seperate items

  • barry
  • Graduate
  • Graduate
  • User avatar
  • Posts: 115
  • Loc: scotland

Post 3+ Months Ago

HI All

I am modding OsCommerce and I have run into a little trouble with a mod.

I am trying to show 2 seperate products in a fading slide show. The slide show is designed only to show 1 product at a time but i want to show 2 which is one under neath the other.

So far i have this:



PHP Code: [ Select ]
<?php
/*Pick specials*/
$special_products_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by rand() limit " . PCS_MAX_DISPLAY_SPECIALS);
 
 
while ($special_product = tep_db_fetch_array($special_products_query)) {
 
$sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='. $special_product['products_id'].' && language_id='.(int)$languages_id;
   $description_query = tep_db_query($sql);
   $description = mysql_fetch_array($description_query, MYSQL_ASSOC);        
   $description['products_description'] = substr($description['products_description'], 0, 150);
   $desc_len = strlen($description['products_description']);
$description['products_description'][$desc_len-1] = '.';
   $description['products_description'][$desc_len-2] = '.';
   $description['products_description'][$desc_len-2] = '.';
 
$description['products_description']  = strip_tags($description['products_description']);
 
 
// this opens the main div which is part of an Jquery slide show
   echo '<div class="PCSChild" alt="'.  htmlspecialchars(html_entity_decode(''))  .'">';
   
   
   
   
   
   // this section shows a product
   echo'<div class="actualbox><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $special_product['products_id']) . '"><img style="float:right;"  src="show_resized_image.php?filename='.DIR_WS_IMAGES . $special_product['products_image'].'&width='.PCS_MAX_IMAGE_WIDTH.'&height='.PCS_MAX_IMAGE_HEIGHT.'" alt="'.$special_product['products_name'].'"><h1>'.$special_product['products_name'].'</h1></a>'.$description['products_description'].'<b style="position:absolute; bottom:0px; right:10px;"><s style="color:red;">'.$currencies->display_price($special_product['products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</s> '.$currencies->display_price($special_product['specials_new_products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</b></div>';
   
   
   // i want this bit to show a different product
   
echo'<div class="actualbox"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $special_product['products_id']) . '"><img style="float:right;"  src="show_resized_image.php?filename='.DIR_WS_IMAGES . $special_product['products_image'].'&width='.PCS_MAX_IMAGE_WIDTH.'&height='.PCS_MAX_IMAGE_HEIGHT.'" alt="'.$special_product['products_name'].'"><h1>'.$special_product['products_name'].'</h1></a>'.$description['products_description'].'<b style="position:absolute; bottom:0px; right:10px;"><s style="color:red;">'.$currencies->display_price($special_product['products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</s> '.$currencies->display_price($special_product['specials_new_products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</b></div>';
 
 
//this closes the jquery slide
 
   echo'</div>';
   
}
?>
  1. <?php
  2. /*Pick specials*/
  3. $special_products_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by rand() limit " . PCS_MAX_DISPLAY_SPECIALS);
  4.  
  5.  
  6. while ($special_product = tep_db_fetch_array($special_products_query)) {
  7.  
  8. $sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='. $special_product['products_id'].' && language_id='.(int)$languages_id;
  9.    $description_query = tep_db_query($sql);
  10.    $description = mysql_fetch_array($description_query, MYSQL_ASSOC);        
  11.    $description['products_description'] = substr($description['products_description'], 0, 150);
  12.    $desc_len = strlen($description['products_description']);
  13. $description['products_description'][$desc_len-1] = '.';
  14.    $description['products_description'][$desc_len-2] = '.';
  15.    $description['products_description'][$desc_len-2] = '.';
  16.  
  17. $description['products_description']  = strip_tags($description['products_description']);
  18.  
  19.  
  20. // this opens the main div which is part of an Jquery slide show
  21.    echo '<div class="PCSChild" alt="'.  htmlspecialchars(html_entity_decode(''))  .'">';
  22.    
  23.    
  24.    
  25.    
  26.    
  27.    // this section shows a product
  28.    echo'<div class="actualbox><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $special_product['products_id']) . '"><img style="float:right;"  src="show_resized_image.php?filename='.DIR_WS_IMAGES . $special_product['products_image'].'&width='.PCS_MAX_IMAGE_WIDTH.'&height='.PCS_MAX_IMAGE_HEIGHT.'" alt="'.$special_product['products_name'].'"><h1>'.$special_product['products_name'].'</h1></a>'.$description['products_description'].'<b style="position:absolute; bottom:0px; right:10px;"><s style="color:red;">'.$currencies->display_price($special_product['products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</s> '.$currencies->display_price($special_product['specials_new_products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</b></div>';
  29.    
  30.    
  31.    // i want this bit to show a different product
  32.    
  33. echo'<div class="actualbox"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $special_product['products_id']) . '"><img style="float:right;"  src="show_resized_image.php?filename='.DIR_WS_IMAGES . $special_product['products_image'].'&width='.PCS_MAX_IMAGE_WIDTH.'&height='.PCS_MAX_IMAGE_HEIGHT.'" alt="'.$special_product['products_name'].'"><h1>'.$special_product['products_name'].'</h1></a>'.$description['products_description'].'<b style="position:absolute; bottom:0px; right:10px;"><s style="color:red;">'.$currencies->display_price($special_product['products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</s> '.$currencies->display_price($special_product['specials_new_products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</b></div>';
  34.  
  35.  
  36. //this closes the jquery slide
  37.  
  38.    echo'</div>';
  39.    
  40. }
  41. ?>



AS you can see from the php this only shows the same item twice. I want to be able to show 2 different products instead of two the same.

You can see it in action here

www DOT bodytone2 DOT biz


Any help would be greatly appreciated ;)
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

I think you're going about it the wrong way. AFIACT, you don't need that second portion in there - you need to find where they're setting the value of PCS_MAX_DISPLAY_SPECIALS and change that from 1 to 2. The while loop should get both on the screen for you.
  • barry
  • Graduate
  • Graduate
  • User avatar
  • Posts: 115
  • Loc: scotland

Post 3+ Months Ago

no thats not the case. The PCS_MAX_DISPLAY_SPECIALS is set to 10. The rest of the listings are loaded in turn using AJAX. I tried to get it to work by doing id id%2 then do show the first one and if not show the second one but that didnt work because the database query has alrtead happened. I was thinking about using "select count from" and if it is odd only show odd then run the whole thing again and if its even show even but the code is for to long and im pretty sure im barking up the wrong tree with that idea anyway....
  • barry
  • Graduate
  • Graduate
  • User avatar
  • Posts: 115
  • Loc: scotland

Post 3+ Months Ago

woo hoo 100 posts .. been here 4 years though ;)
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

oooh, I should have checked the link, sorry. I see what's going on with it now. Each product gets it's own 'slide'. Sooo for you...why not remove the second section, start a simple iterator to keep count in your while loop, and then only echo the closing div if it's following an even iteration? That should put two per slide.

Code: [ Select ]
<?php
/*Pick specials*/
$special_products_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by rand() limit " . PCS_MAX_DISPLAY_SPECIALS);

$iter = 0;
while ($special_product = tep_db_fetch_array($special_products_query)) {
$iter++;
$sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='. $special_product['products_id'].' && language_id='.(int)$languages_id;
  $description_query = tep_db_query($sql);
  $description = mysql_fetch_array($description_query, MYSQL_ASSOC);  
  $description['products_description'] = substr($description['products_description'], 0, 150);
  $desc_len = strlen($description['products_description']);
$description['products_description'][$desc_len-1] = '.';
  $description['products_description'][$desc_len-2] = '.';
  $description['products_description'][$desc_len-2] = '.';

$description['products_description'] = strip_tags($description['products_description']);


// this opens the main div which is part of an Jquery slide show
  echo '<div class="PCSChild" alt="'. htmlspecialchars(html_entity_decode('')) .'">';
  
  
  
  
  
  // this section shows a product
  echo'<div class="actualbox><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $special_product['products_id']) . '"><img style="float:right;" src="show_resized_image.php?filename='.DIR_WS_IMAGES . $special_product['products_image'].'&width='.PCS_MAX_IMAGE_WIDTH.'&height='.PCS_MAX_IMAGE_HEIGHT.'" alt="'.$special_product['products_name'].'"><h1>'.$special_product['products_name'].'</h1></a>'.$description['products_description'].'<b style="position:absolute; bottom:0px; right:10px;"><s style="color:red;">'.$currencies->display_price($special_product['products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</s> '.$currencies->display_price($special_product['specials_new_products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</b></div>';
  
  
//this closes the jquery slide

  if($iter % 2 == 0) {
    echo'</div>';
  }
  
}
?>
  1. <?php
  2. /*Pick specials*/
  3. $special_products_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by rand() limit " . PCS_MAX_DISPLAY_SPECIALS);
  4. $iter = 0;
  5. while ($special_product = tep_db_fetch_array($special_products_query)) {
  6. $iter++;
  7. $sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='. $special_product['products_id'].' && language_id='.(int)$languages_id;
  8.   $description_query = tep_db_query($sql);
  9.   $description = mysql_fetch_array($description_query, MYSQL_ASSOC);  
  10.   $description['products_description'] = substr($description['products_description'], 0, 150);
  11.   $desc_len = strlen($description['products_description']);
  12. $description['products_description'][$desc_len-1] = '.';
  13.   $description['products_description'][$desc_len-2] = '.';
  14.   $description['products_description'][$desc_len-2] = '.';
  15. $description['products_description'] = strip_tags($description['products_description']);
  16. // this opens the main div which is part of an Jquery slide show
  17.   echo '<div class="PCSChild" alt="'. htmlspecialchars(html_entity_decode('')) .'">';
  18.   
  19.   
  20.   
  21.   
  22.   
  23.   // this section shows a product
  24.   echo'<div class="actualbox><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $special_product['products_id']) . '"><img style="float:right;" src="show_resized_image.php?filename='.DIR_WS_IMAGES . $special_product['products_image'].'&width='.PCS_MAX_IMAGE_WIDTH.'&height='.PCS_MAX_IMAGE_HEIGHT.'" alt="'.$special_product['products_name'].'"><h1>'.$special_product['products_name'].'</h1></a>'.$description['products_description'].'<b style="position:absolute; bottom:0px; right:10px;"><s style="color:red;">'.$currencies->display_price($special_product['products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</s> '.$currencies->display_price($special_product['specials_new_products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</b></div>';
  25.   
  26.   
  27. //this closes the jquery slide
  28.   if($iter % 2 == 0) {
  29.     echo'</div>';
  30.   }
  31.   
  32. }
  33. ?>
  • barry
  • Graduate
  • Graduate
  • User avatar
  • Posts: 115
  • Loc: scotland

Post 3+ Months Ago

that dosnt work either.. It does however show two different products but then nothing else. The thing is the two seperate products need to go into the PCSChild layer at the same time so the layout would be like this:



main div holding everything
btw i have put them in order but as you can see from the query they are random. I dont realy care about the order and if i can get it to work i will change random to ordered if it will make life simpler.

PCSChild fades in

product 1
product 2

end of PCSChild faides out

PCSChild fades in

product 3
product 4

end of PCSChild faides out

PCSChild fades in

product 5
product 6

end of PCSChild faides out

and so on up to end of the while loop

I tried to just add a 1 to the id of the second product but that didnt work

Think ill go watch some crap on tv just now till my head gets round whats happening. I would love to hear your sugestions though and thanks much for the help so far!
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

doh - the opener - I forgot the opener. Try this:

Code: [ Select ]
<?php
/*Pick specials*/
$special_products_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by rand() limit " . PCS_MAX_DISPLAY_SPECIALS);

$iter = 0;
while ($special_product = tep_db_fetch_array($special_products_query)) {
$iter++;
$sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='. $special_product['products_id'].' && language_id='.(int)$languages_id;
  $description_query = tep_db_query($sql);
  $description = mysql_fetch_array($description_query, MYSQL_ASSOC);  
  $description['products_description'] = substr($description['products_description'], 0, 150);
  $desc_len = strlen($description['products_description']);
$description['products_description'][$desc_len-1] = '.';
  $description['products_description'][$desc_len-2] = '.';
  $description['products_description'][$desc_len-2] = '.';

$description['products_description'] = strip_tags($description['products_description']);


// this opens the main div which is part of an Jquery slide show
 if($iter % 2 == 1) {
    echo '<div class="PCSChild" alt="'. htmlspecialchars(html_entity_decode('')) .'">';
 }
  
  
  
  
    // this section shows a product
  echo'<div class="actualbox><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $special_product['products_id']) . '"><img style="float:right;" src="show_resized_image.php?filename='.DIR_WS_IMAGES . $special_product['products_image'].'&width='.PCS_MAX_IMAGE_WIDTH.'&height='.PCS_MAX_IMAGE_HEIGHT.'" alt="'.$special_product['products_name'].'"><h1>'.$special_product['products_name'].'</h1></a>'.$description['products_description'].'<b style="position:absolute; bottom:0px; right:10px;"><s style="color:red;">'.$currencies->display_price($special_product['products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</s> '.$currencies->display_price($special_product['specials_new_products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</b></div>';
  
  
//this closes the jquery slide

  if($iter % 2 == 0) {
    echo'</div>';
  }
  
}
?>
  1. <?php
  2. /*Pick specials*/
  3. $special_products_query = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_price, p.products_tax_class_id, p.products_image, s.specials_new_products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_SPECIALS . " s where p.products_status = '1' and p.products_id = s.products_id and pd.products_id = s.products_id and pd.language_id = '" . (int)$languages_id . "' and s.status = '1' order by rand() limit " . PCS_MAX_DISPLAY_SPECIALS);
  4. $iter = 0;
  5. while ($special_product = tep_db_fetch_array($special_products_query)) {
  6. $iter++;
  7. $sql = 'SELECT `products_description` FROM `products_description` WHERE products_id ='. $special_product['products_id'].' && language_id='.(int)$languages_id;
  8.   $description_query = tep_db_query($sql);
  9.   $description = mysql_fetch_array($description_query, MYSQL_ASSOC);  
  10.   $description['products_description'] = substr($description['products_description'], 0, 150);
  11.   $desc_len = strlen($description['products_description']);
  12. $description['products_description'][$desc_len-1] = '.';
  13.   $description['products_description'][$desc_len-2] = '.';
  14.   $description['products_description'][$desc_len-2] = '.';
  15. $description['products_description'] = strip_tags($description['products_description']);
  16. // this opens the main div which is part of an Jquery slide show
  17.  if($iter % 2 == 1) {
  18.     echo '<div class="PCSChild" alt="'. htmlspecialchars(html_entity_decode('')) .'">';
  19.  }
  20.   
  21.   
  22.   
  23.   
  24.     // this section shows a product
  25.   echo'<div class="actualbox><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $special_product['products_id']) . '"><img style="float:right;" src="show_resized_image.php?filename='.DIR_WS_IMAGES . $special_product['products_image'].'&width='.PCS_MAX_IMAGE_WIDTH.'&height='.PCS_MAX_IMAGE_HEIGHT.'" alt="'.$special_product['products_name'].'"><h1>'.$special_product['products_name'].'</h1></a>'.$description['products_description'].'<b style="position:absolute; bottom:0px; right:10px;"><s style="color:red;">'.$currencies->display_price($special_product['products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</s> '.$currencies->display_price($special_product['specials_new_products_price'], tep_get_tax_rate($special_product['products_tax_class_id'])).'</b></div>';
  26.   
  27.   
  28. //this closes the jquery slide
  29.   if($iter % 2 == 0) {
  30.     echo'</div>';
  31.   }
  32.   
  33. }
  34. ?>
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

Quote:
woo hoo 100 posts .. been here 4 years though ;)


It's like boiling water - the harder you stare at it, the slower it goes. :)
  • barry
  • Graduate
  • Graduate
  • User avatar
  • Posts: 115
  • Loc: scotland

Post 3+ Months Ago

you my freind are a star!!!

It works perfectly ... all i need to do is a little css tweek,ing and all is well at the ranch!!

Thanks too much for helping me out! :D :D :D
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

You're welcome. Next time I'll try to catch my mistakes in the first suggestion. ;)

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 80 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.