Vixushr Posted May 13, 2011 Share Posted May 13, 2011 Helo dear people, I need some help with piece of code that generates XML This all works as is: include(dirname(__FILE__).'/config/config.inc.php'); require_once(dirname(__FILE__).'/init.php'); error_reporting(0); $p=Product::getProducts(7, 0, 0, 'id_product', 'desc', false); $products=Product::getProductsProperties(7, $p); header("Content-Type: text/xml\n\n"); //print "Content-type: text/html\n\n"; echo '<?xml version="1.0" encoding="utf-8"?> <Catalog>'; foreach ($products as $row) { if ($row['active']){ $img=Product::getCover($row['id_product']); echo ' <products> <code>'.str_replace("&", "&", $row['id_product']).'</code> <name>'.str_replace("&", "&", $row['name']).'</name> <descr>'.str_replace("&", "and", strip_tags($row['description_short'])).'</descr> <price>'.($row['price']*1).'</price> <quantity>'.str_replace("&", "&", $row['quantity']).'</quantity> <categ>'.str_replace("&", "&", $row['category']).'</categ> <link>http://www.xxxxx.hr'.$row['link'].'</link> <img>http://www.xxxxx.hr/xxxxx/'.$shopUrl.'img/p/'.$row['id_product'].'-'.$img['id_image'].'.jpg</img> </products>'; } } echo '</Catalog>'; ?>code] But now i need to hide quantity if its larger that 5 pieces. So that all quantity that is >= equal or larger of 5 si shown in XML as 5. Can anyone help me out with this!? :'( BR Vixus Quote Link to comment Share on other sites More sharing options...
Vixushr Posted May 13, 2011 Author Share Posted May 13, 2011 Uh i see a small error, this piece of my text ended in code section. and theres no more modify button. So here it is! I need to hide quantity that is greather than 5 pieces. So that all quantity that is >= equal or larger than 5 is shown in XML as 5. eg. if quantity is 129 in xml is reported as 5. Can anyone help me out with this!? BR Quote Link to comment Share on other sites More sharing options...
Vixushr Posted May 13, 2011 Author Share Posted May 13, 2011 Can anyone help me??? I assume that i need some if else but i cant get it right... I was trying to add this: if ($row['quantity'] >= 5) { $return = "5"; } else { $return = $row['quantity']; } But it wont work... Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 13, 2011 Share Posted May 13, 2011 I was trying to add this: if ($row['quantity'] >= 5) { $return = "5"; } else { $return = $row['quantity']; } But it wont work... Of course it doesn't you aren't "returning" the value, you are echoing the value into an XML file. So, if the value is >5, then redefine the value as five. Then the 5 will get written to the file. Put this right before the echo statement: if ($row['quantity'] >= 5) { $row['quantity'] = "5"; } Quote Link to comment Share on other sites More sharing options...
Vixushr Posted May 13, 2011 Author Share Posted May 13, 2011 Thanx mate, easy and eficient. Can i offer you a paypall beer? Quote Link to comment Share on other sites More sharing options...
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.