NodsDorf Posted June 6, 2012 Share Posted June 6, 2012 I need a little help here, my brain is stuck. I need to check a field inside our products table to get a products lead time. Then put it in the product_listing. I have used this query on our shopping cart page and it works. //STOCK NOTICE CODE $stock_time_query = tep_db_query("select p.products_lead_time as lead_time FROM " . TABLE_PRODUCTS . " p where p.products_id= '" . $products[$i]['id'] . "'"); while ($stock_time = tep_db_fetch_array($stock_time_query)) { if ($stock_time['lead_time']>0) { $stock_notice = sprintf(STOCK_TIME_NOTICE, $products[$i]["model"], $stock_time["lead_time"]); } } ////END STOCK NOTICE CODE I'm trying to slip the value for our product listing results so if stock is 0 then we display lead time . I've tried slipping in here case 'PRODUCT_LIST_QUANTITY': ////SLIPPED IN HERE.. don't work ////CHECKING IF STOCK = 0 if ($listing[$x]['products_quantity']=='0' && substr($listing[$x]['products_model'],0,1) =='B') { $prod_list_contents .= ' <td align="right">' . TEXT_RESTOCK_BELLOW . '</td>'; }else if ($listing[$x]['products_quantity']=='0' && substr($listing[$x]['products_model'],0,1) !='B'){ $prod_list_contents .= ' <td align="right">'. TEXT_RESTOCK_ORING . '</td>'; ///IF STOCK NOT = 0 THEN GIVE QUANTITY } else{ $prod_list_contents .= ' <td align="right">' . $listing[$x]['products_quantity'] . '</td>'; } break; I have 2 messages one for our orings and one for our bellows are bellows are the issue as depending on the type the lead time can be 2 weeks up to 10 weeks. So i tried to change $stock_notice = sprintf(STOCK_TIME_NOTICE, $products[$i]["model"], $stock_time["lead_time"]); into $stock_notice = sprintf(TEXT_RESTOCK_BELLOW, $products[$i]["model"], $stock_time["lead_time"]); Then defined it as define('TEXT_RESTOCK_BELLOW', '<b>%d Weeks*</b>'); But I'm getting exactly that outputted if its a Bellow and the Stock is 0 I get %d Weeks as the quantity. What I want to see in the quantity field is 2 Weeks or 10 Weeks whatever the lead time value is. The other thing I am concerned with is running a query inside a loop or a case statement that can't be good.. Any help with this one? Thanks Link to comment Share on other sites More sharing options...
germ Posted June 7, 2012 Share Posted June 7, 2012 Looking at this: define('TEXT_RESTOCK_BELLOW', '<b>%d Weeks*</b>'); $stock_notice = sprintf(TEXT_RESTOCK_BELLOW, $products[$i]["model"], $stock_time["lead_time"]); You're trying to print TWO variables, but only one format. Maybe this: define('TEXT_RESTOCK_BELLOW', '<b>%s %d Weeks*</b>'); $stock_notice = sprintf(TEXT_RESTOCK_BELLOW, $products[$i]["model"], (int)$stock_time["lead_time"]); That way $products[$i]["model"] gets printed in the %s and $stock_time["lead_time"] gets printed in the %d If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
NodsDorf Posted June 7, 2012 Author Share Posted June 7, 2012 Thanks Jim, I tried that as well, I end up with %s %d Weeks as the value. I think my issue is more with the function //STOCK NOTICE CODE $stock_time_query = tep_db_query("select p.products_lead_time as lead_time FROM " . TABLE_PRODUCTS . " p where p.products_id= '" . $products[$i]['id'] . "'"); while ($stock_time = tep_db_fetch_array($stock_time_query)) { if ($stock_time['lead_time']>0) { $stock_notice = sprintf(TEXT_RESTOCK_BELLOW, $products[$i]["model"], $stock_time["lead_time"]); } } ////END STOCK NOTICE CODE Since the product listing uses some funky array matching like $listing[$x]['product_model] Here is most of the page.. // while ($listing = tep_db_fetch_array($listing_query)) { (was original code) for ($x = 0; $x < $no_of_listings; $x++) { $rows++; $prod_list_contents .= ' <tr>'; for ($col=0, $n=sizeof($column_list); $col<$n; $col++) { switch ($column_list[$col]) { case 'PRODUCT_LIST_MODEL': $prod_list_contents .= ' <td>' . $listing[$x]['products_model'] . '</td>'; break; case 'PRODUCT_LIST_NAME': /*** Begin Header Tags SEO ***/ $lc_add = '</td>'; $hts_listing_query = tep_db_query("select products_head_listing_text, products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id = " . (int)$listing['products_id'] . " and language_id = " . (int)$languages_id); if (tep_db_num_rows($hts_listing_query) > 0) { $hts_listing = tep_db_fetch_array($hts_listing_query); if (tep_not_null($hts_listing['products_head_listing_text'])) { $lc_add = '<div class="hts_listing_text">' . $hts_listing['products_head_listing_text'] . '...<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing[$x]['products_id']) . '"><span style="color:red;">' . TEXT_SEE_MORE . '</span></a></div></td>'; } else if (HEADER_TAGS_ENABLE_AUTOFILL_LISTING_TEXT == 'true') { $text = sprintf("%s...%s", substr(stripslashes($hts_listing['products_description']), 0, 100), '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . (int)$listing['products_id']) . '"><span style="color:red;">' . TEXT_SEE_MORE . '</span></a>'); $lc_add = '<div class="hts_listing_text">' . $text . '</div></td>'; } } if (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) { $prod_list_contents .= ' <td><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing[$x]['products_id']) . '">' . $listing[$x]['products_name'] . '</a>'; $prod_list_contents .= $lc_add; } else { $prod_list_contents .= ' <td><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing[$x]['products_id']) . '">' . $listing[$x]['products_name'] . '</a>'; $prod_list_contents .= $lc_add; } /*** End Header Tags SEO ***/ break; case 'PRODUCT_LIST_MANUFACTURER': $prod_list_contents .= ' <td><a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing[$x]['manufacturers_id']) . '">' . $listing[$x]['manufacturers_name'] . '</a></td>'; break; case 'PRODUCT_LIST_PRICE': $price_breaks_from_listing = array(); if (isset($price_breaks_array[$listing[$x]['products_id']])) { $price_breaks_from_listing = $price_breaks_array[$listing[$x]['products_id']]; } $pf->loadProduct($listing[$x]['products_id'], $languages_id, $listing[$x], $price_breaks_from_listing); $prod_list_contents .= ' <td align="right">' . $pf->getPriceStringShort(). '</td>'; break; case 'PRODUCT_LIST_QUANTITY': ////CHECKING IF STOCK = O if ($listing[$x]['products_quantity']=='0' && substr($listing[$x]['products_model'],0,1) =='B') { $prod_list_contents .= ' <td align="right">' . TEXT_RESTOCK_BELLOW . '</td>'; }else if ($listing[$x]['products_quantity']=='0' && substr($listing[$x]['products_model'],0,1) !='B'){ $prod_list_contents .= ' <td align="right">'. TEXT_RESTOCK_ORING . '</td>'; ///IF STOCK NOT = 0 THEN GIVE QUANTITY } else{ $prod_list_contents .= ' <td align="right">' . $listing[$x]['products_quantity'] . '</td>'; } break; case 'PRODUCT_LIST_WEIGHT': $prod_list_contents .= ' <td align="right">' . $listing[$x]['products_weight'] . '</td>'; break; case 'PRODUCT_LIST_IMAGE': if (isset($HTTP_GET_VARS['manufacturers_id']) && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) { $prod_list_contents .= ' <td align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing[$x]['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing[$x]['products_image'], $listing[$x]['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>'; } else { $prod_list_contents .= ' <td align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing[$x]['products_id']) . '">' . tep_image(DIR_WS_IMAGES . $listing[$x]['products_image'], $listing[$x]['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>'; } break; case 'PRODUCT_LIST_BUY_NOW': // $prod_list_contents .= ' <td align="center">' . tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action', 'products_id')) . 'action=buy_now&products_id=' . $listing[$x]['products_id'])) . '</td>'; $prod_list_contents .= ' <td align="center">' . tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action', 'products_id')) . 'action=buy_now&products_id=' . $listing[$x]['products_id']), NULL, array('params'=>'rel="nofollow"')) . '</td>'; break; } } $prod_list_contents .= ' </tr>'; } $prod_list_contents .= ' </table>' . ' </div>' . '</div>'; echo $prod_list_contents; Link to comment Share on other sites More sharing options...
germ Posted June 7, 2012 Share Posted June 7, 2012 sprintf() returns the formatted string so: $stock_notice = sprintf(TEXT_RESTOCK_BELLOW, $products[$i]["model"], $stock_time["lead_time"]); To show the result of that you need something like this: echo $stock_notice; Not: echo TEXT_RESTOCK_BELLOW; Get the drift? :unsure: If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
NodsDorf Posted June 7, 2012 Author Share Posted June 7, 2012 Humm I may feel real stupid in a second... Checking... Link to comment Share on other sites More sharing options...
germ Posted June 7, 2012 Share Posted June 7, 2012 Not "stupid". Sometimes when you try to look at the forest, all them d*mn trees get in the way.... (w00t) If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
NodsDorf Posted June 7, 2012 Author Share Posted June 7, 2012 Color me tarded Thanks Jim That was it... I did have to change the function a little case 'PRODUCT_LIST_QUANTITY': //STOCK NOTICE CODE $stock_time_query = tep_db_query("select p.products_lead_time as lead_time FROM " . TABLE_PRODUCTS . " p where p.products_model= '" . $listing[$x]['products_model'] . "'"); while ($stock_time = tep_db_fetch_array($stock_time_query)) { if ($stock_time['lead_time']>0) { $stock_notice = sprintf(TEXT_RESTOCK_BELLOW, $listing[$x]['products_model'], $stock_time['lead_time']); } } ////END STOCK NOTICE CODE ////CHECKING IF STOCK = O if ($listing[$x]['products_quantity']=='0' && substr($listing[$x]['products_model'],0,1) =='B') { $prod_list_contents .= ' <td align="right">' . $stock_notice. '</td>'; }else if ($listing[$x]['products_quantity']=='0' && substr($listing[$x]['products_model'],0,1) !='B'){ $prod_list_contents .= ' <td align="right">'. TEXT_RESTOCK_ORING . '</td>'; ///IF STOCK NOT = 0 THEN GIVE QUANTITY } else{ $prod_list_contents .= ' <td align="right">' . $listing[$x]['products_quantity'] . '</td>'; } break; Now I'm getting "$model X Weeks, exactly what I would expect. I guess my next question is.. I don't want to display the model and using %s by itself don't work. Any thoughts on that? Link to comment Share on other sites More sharing options...
germ Posted June 7, 2012 Share Posted June 7, 2012 define('TEXT_RESTOCK_BELLOW', '<b>%d Weeks*</b>'); $stock_notice = sprintf(TEXT_RESTOCK_BELLOW, $stock_time['lead_time']); If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there > Link to comment Share on other sites More sharing options...
NodsDorf Posted June 7, 2012 Author Share Posted June 7, 2012 Thanks Jim, For some reason I was under the assumption sprintf() required 2 variables. Long week and its only half over thanks again. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.