Jump to content

HELP with a piece of code


Vixushr

Recommended Posts

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 

Link to comment
https://forums.phpfreaks.com/topic/236319-help-with-a-piece-of-code/
Share on other sites

Uh i see a small error, this piece of my text ended in code section.  :P

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

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";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.