000---000 Posted November 13, 2013 Posted November 13, 2013 I'm trying to create an info box where by each day of the month shows a different product. Just something to keep the site fresh (ish) and controllable. I'm no genius programmer, although I do have a vague idea of what goes on. I've set up a page so far which works out the day of the month, pretty easy. I now want to use that mechanism to define a different product and lay it out. Initially I have... <?php $today=date(d); if($today==1){ echo "<img src='images-by-date/1.jpg'>"; } elseif($today==2){ echo "<img src='images-by-date/2.jpg'>"; } ...and so on. This simply allows me to select a pre chosen image etc. My query is, I want to replace the echo image line with something like &productid=342 and then below the above 31 php elseif statements have an extra section which lays out the data according to that product id. I know how to layout the bottom section once I have a suitable variable to call from, I'm just not sure exactly how I specify the product. For example, I tried something like: if($today==1){ $productid=963; } But this just produced images-by-date/9 ??? When calling/using $productid further down. ie Using: <?php echo $product_info['products_image'] ?> How do I define that on the 1st of the month it always show product 963 for example? Thanks Quote
000---000 Posted November 14, 2013 Author Posted November 14, 2013 (edited) Fantastic. That's put me on the right lines. However, to recall the other product properties, as I realise that I may change a price in one place and not pick it up on the front page, how would I continue this code on? To call the image, description and price... As I think I just need to change the format around and not have a specific product image per day that relates to the product directly. FILENAME_PRODUCT_INFO brings up the "product_info.php/" part etc and the remainder of tep_href_link is the product link... I get that (I hope). DIR_WS_IMAGES gives me the image directory etc, but how do I call the product image from $productid? I've tried all sorts, the most logical seem to be... echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int)$productid) . '">' . tep_image(DIR_WS_IMAGES . $products_image . (int)$productid) . '</a>'; ?> or echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . (int)$productid) . '">' . tep_image(DIR_WS_IMAGES . $productsid['products_image']) . '</a>'; ?> But neither work. I've spent a few hours pulling apart other product listing code to try and give me the correct results. The best I've got is <img src="image/$productsid=963"> Am I misinterpreting the use of $productid here? Edited November 14, 2013 by 000---000 Quote
000---000 Posted December 2, 2013 Author Posted December 2, 2013 (edited) @@burt I finally managed to work something out. By placing the following on the index page: <?php require('includes/daterotate.php');?> And then creating the following daterotate.php file, DEFINED in filenames.php too: <?php switch (date("d")) { case 1: $productid = 134; break; case 2: $productid = 538; .... case 31: $productid = 386; break; } $date_product_info_query = tep_db_query("select p.products_id, pd.products_url, pd.products_name, pd.products_description, p.products_image, p.products_price, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = $productid and pd.products_id = $productid"); $fproduct_info = tep_db_fetch_array($date_product_info_query); $products_price = $currencies->display_price($fproduct_info['products_price'], tep_get_tax_rate($fproduct_info['products_tax_class_id'])); echo '<table width=100% bgcolor="#eeeeee"><tr><td><h1>' . $fproduct_info['products_name'] . '</h1><br><br>' . $products_price . '<br><a href="' . tep_href_link(FILENAME_PRODUCT_INFO . '?products_id=' . (int)$productid) . '" width="100" height="100">' . tep_image(DIR_WS_IMAGES . $fproduct_info['products_image'], addslashes($fproduct_info['products_name']), 200, 200, 'hspace="5" vspace="5"') . '</a></td><td>' . $fproduct_info['products_description'] . '</td></tr></table>'; ?> Result: I created a table on the index page, which allows me to link a daily products, as per the case variable. Just thought I'd share it. I'm sure this is quite easy for some. Thanks for the help. Matt Edited December 2, 2013 by 000---000 Quote
000---000 Posted January 15, 2014 Author Posted January 15, 2014 (edited) Another way I've found of doing it... <?php class foo { var $arr = array('134', '538', '553', '386', '538', '552', '134', '430', '545', '553', '548', '538', '553', '550', '538', '548', '550', '546', '548', '349', '348', '545', '538', '364', '552', '348', '349', '545', '364', '546', '386', '134'); } $foo = new foo(); $arr = 'arr'; $productid = $foo->{$arr}[date("d")]; $date_product_info_query = tep_db_query("select p.products_id, pd.products_url, pd.products_name, pd.products_description, p.products_image, p.products_price, p.products_quantity, p.products_tax_class_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = $productid and pd.products_id = $productid"); $fproduct_info = tep_db_fetch_array($date_product_info_query); $products_price = $currencies->display_price($fproduct_info['products_price'], tep_get_tax_rate($fproduct_info['products_tax_class_id'])); echo '<table width=100% bgcolor="#ddddff" border=0><tr><td><h1>Todays featured product:</h1></td><tr><tr><td>'; echo '<table width=100% bgcolor="#eeeeff" CELLPADDING=5><tr> <td valign="top"> <table width=100% bgcolor="#eeeeff" height="100%"><tr><td valign="Top"> <a href="' . tep_href_link(FILENAME_PRODUCT_INFO . '?products_id=' . (int)$productid) . '" width="100" height="100"><h1>' . $fproduct_info['products_name'] . '</h1></a><br><br>' . $products_price . ' </td></tr> <tr><td vvalign="bottom"> <a href="' . tep_href_link(FILENAME_PRODUCT_INFO . '?products_id=' . (int)$productid) . '" width="100" height="100">' . tep_image(DIR_WS_IMAGES . $fproduct_info['products_image'], addslashes($fproduct_info['products_name']), 200, 200, 'hspace="5" vspace="5"') . '</a>' . '</td> </td></tr></table> <td bgcolor="#ffffff">'; $prod_link2 = tep_href_link(FILENAME_PRODUCT_INFO . '?products_id=' . (int)$productid); function custom_echo($x) { if(strlen($x)<=2000) { echo $x; } else { $y=substr($x,0,2000) . '...more...'; echo $y; } } echo custom_echo($fproduct_info['products_description']) . '</td></tr></table>'; echo '</td></tr></table>'; ?> The last bit shortens the product listing/description to 2000 characters. File listed in filenames.php and then called into position via "require('whateveryousavedthisfileas.php');" Edited January 15, 2014 by 000---000 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.