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
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

Link to comment
Share on other sites

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...  :(

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.