Guest Posted January 13, 2009 Share Posted January 13, 2009 I have the following line of code in my product_listing.php file. <a href="<?= tep_href_link("products_new.php","action=buy_now&products_id=".$new_p_id[$i-1])?>"><?=tep_image_button("button_add_to_cart1.gif");?></a> If the product is out of stock I want to display a different image, i.e soldout.gif. I have trid the following, but when I load it up I can just see the text of the whole IF statement in my browser. Does anyone know where I am going wrong? //BEGIN SOLDOUT if ($listing['products_quantity']>-0) { <a href="<?= tep_href_link("products_new.php","action=buy_now&products_id=".$new_p_id[$i-1])?>"><?=tep_image_button("button_add_to_cart1.gif");?></a> } else{ <a href="<?= tep_href_link("products_new.php","action=buy_now&products_id=".$new_p_id[$i-1])?>"><?=tep_image_button("soldout.gif");?></a> } //END SOLDOUT Link to comment Share on other sites More sharing options...
burt Posted January 13, 2009 Share Posted January 13, 2009 Because it's not all PHP. You have some HTML and some PHP in each line of code, hence you must start and stop your PHP properly. Link to comment Share on other sites More sharing options...
Guest Posted January 13, 2009 Share Posted January 13, 2009 Because it's not all PHP. You have some HTML and some PHP in each line of code, hence you must start and stop your PHP properly. Ah I see. Im totally not used to coding, I dont suppose you know how I would do this....is it even possible? Link to comment Share on other sites More sharing options...
Guest Posted January 13, 2009 Share Posted January 13, 2009 Ah I see. Im totally not used to coding, I dont suppose you know how I would do this....is it even possible? Any pointer in the right direction would really be appreciated with this. Spent a couple of days on it so far. Link to comment Share on other sites More sharing options...
Guest Posted January 13, 2009 Share Posted January 13, 2009 Like Burt said, you have php and html mixed. You need an opening and closing php tag for the php. Try something like this <?php //BEGIN SOLDOUT if ($listing['products_quantity']>-0) { ?> <a href="<?= tep_href_link("products_new.php","action=buy_now&products_id=".$new_p_id[$i-1])?>"><?=tep_image_button("button_add_to_cart1.gif");?></a> <?php } else { ?> <a href="<?= tep_href_link("products_new.php","action=buy_now&products_id=".$new_p_id[$i-1])?>"><?=tep_image_button("soldout.gif");?></a> <?php } //END SOLDOUT ?> Link to comment Share on other sites More sharing options...
Guest Posted January 13, 2009 Share Posted January 13, 2009 Like Burt said, you have php and html mixed. You need an opening and closing php tag for the php. Try something like this <?php //BEGIN SOLDOUT if ($listing['products_quantity']>-0) { ?> <a href="<?= tep_href_link("products_new.php","action=buy_now&products_id=".$new_p_id[$i-1])?>"><?=tep_image_button("button_add_to_cart1.gif");?></a> <?php } else { ?> <a href="<?= tep_href_link("products_new.php","action=buy_now&products_id=".$new_p_id[$i-1])?>"><?=tep_image_button("soldout.gif");?></a> <?php } //END SOLDOUT ?> Thanks so much, thats been an amazing help and saved me hours...and I've learnt something about PHP!! However, its still not working, but I think there is an issue with the original code. The line that isnt working is; if ($listing['products_quantity']>-0) This if statement isnt capturing products which have 1 or more in stock, everytime its just going to the ELSE part of the statement. So every single product is getting the soldout.gif I've tried changing it to; if ($listing['products_quantity']>-0) But that still doesnt work. Just for clarity, my current code is; <?php //BEGIN SOLDOUT if ($listing['products_quantity']>-0) { ?> <a href="<?= tep_href_link("products_new.php","action=buy_now&products_id=".$new_p_id[$i-1])?>"><?=tep_image_button("button_add_to_cart1.gif");?></a> <?php } else { ?> <a href="<?= tep_href_link("products_new.php","action=buy_now&products_id=".$new_p_id[$i-1])?>"><?=tep_image_button("soldout.gif");?></a> <?php } //END SOLDOUT ?> Does anyone have any ideas why it is ALWAYS doing soldout.giof and never button_add_to_cart1.gif? Link to comment Share on other sites More sharing options...
germ Posted January 13, 2009 Share Posted January 13, 2009 Try changing this line: if ($listing['products_quantity']>0) { To if ( tep_get_products_stock( $new_p_id[$i-1] ) > 0 ) { 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...
Guest Posted January 13, 2009 Share Posted January 13, 2009 Try changing this line: if ($listing['products_quantity']>0) { To if ( tep_get_products_stock( $new_p_id[$i-1] ) > 0 ) { My friend you are a genius! Worked perfect. I dont suppose you could explain what that did and why the original didnt work....just so I can get my head around it? Thanks again. Link to comment Share on other sites More sharing options...
germ Posted January 13, 2009 Share Posted January 13, 2009 The only reason the other code didn't work was this variable: $listing['products_quantity'] Didn't contain correct information (for whatever reason). 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...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.