Skip to main content
Inspiring
Dec 18, 2013 9:48 PM UTC
Answered

hide echo using ! not working

i have two prices the price and a discount, some products have the discount a couple dont if they dont have the discount i want to have hide the price as below

<? if (!$row_rsProduct['Product'] == 'prod1'):

                    ?>

<?php echo DoFormatCurrency($row_rsProduct['Price'], 2, '.', '.', '£ ', ''); ?>

<?php endif; ?>

<?php echo DoFormatCurrency($row_rsProduct['Discount'], 2, '.', '.', '£ ', ''); ?>

This topic is closed to new replies. Start a new post to keep the conversation going.
Rob Hecker2
Rob Hecker2Correct answer
Legend
Dec 19, 2013 12:27 PM UTC

Is there a reason you are wrapping every line of code in script tags?

Is prod1 a variable, a costant, or a literal? If a variable, begin with a dollar sign. If a constant, make it all caps (that's for the sake of convention) and don't wrap in single quotes. If a literal, then leave the way you had it. I suspect you intended a variable.

if ($row_rsProduct['Product'] != $prod1){

               echo DoFormatCurrency($row_rsProduct['Price'], 2, '.', '.', '£ ', '');

}

echo DoFormatCurrency($row_rsProduct['Discount'], 2, '.', '.', '£ ', '');

7 replies

Rob Hecker2
Rob Hecker2Correct answer
Legend
Dec 19, 2013 12:27 PM UTC

Is there a reason you are wrapping every line of code in script tags?

Is prod1 a variable, a costant, or a literal? If a variable, begin with a dollar sign. If a constant, make it all caps (that's for the sake of convention) and don't wrap in single quotes. If a literal, then leave the way you had it. I suspect you intended a variable.

if ($row_rsProduct['Product'] != $prod1){

               echo DoFormatCurrency($row_rsProduct['Price'], 2, '.', '.', '£ ', '');

}

echo DoFormatCurrency($row_rsProduct['Discount'], 2, '.', '.', '£ ', '');

Translate
Inspiring
Dec 19, 2013 8:32 PM UTC

here is where all the code, a variable was not intented, it is an actual product name that needs to be used

$var1_rsProduct = "-1";

if (isset($_GET['productID'])) {

  $var1_rsProduct = $_GET['productID'];

}

mysql_select_db($database_event, $event);

$query_rsProduct = sprintf("SELECT * FROM eventAW13_Cat, eventAW13_products, eventAW13_Stock, eventAW13_SizeList WHERE eventAW13_products.catID = eventAW13_Cat.catID AND eventAW13_products.ProductID = eventAW13_Stock.ProductID AND eventAW13_Stock.SizeID = eventAW13_SizeList.SizeID AND eventAW13_products.ProductID = %s AND eventAW13_Stock.Stock != 0  ORDER BY eventAW13_Stock.StockID", GetSQLValueString($var1_rsProduct, "int"));

$rsProduct = mysql_query($query_rsProduct, $event) or die(mysql_error());

$row_rsProduct = mysql_fetch_assoc($rsProduct);

$totalRows_rsProduct = mysql_num_rows($rsProduct);

the actual product is "jumper red stripe"

><? if (!$row_rsProduct['Product'] == 'jumper red stripe'):

                    ?><?php echo DoFormatCurrency($row_rsProduct['Price'], 2, '.', '.', '£ ', ''); ?><?php endif; ?><?php echo DoFormatCurrency($row_rsProduct['Discount'], 2, '.', '.', '£ ', ''); ?>

in the database i have two columns the "Discount and the "Price" if something does not have a discount they have the same price in both so only need the discount one showing thus hide the "Price".

Translate
Participating Frequently
Dec 19, 2013 9:29 PM UTC

I'll repeat my question from earlier:

"Show us an example of the output you are getting and include the value of the 'Product' field."

You haven't explained to us how this code is misbehaving. What's it doing?

Like Rob, I also don't understand why you are wrapping each line in script tags.

Translate
Participating Frequently
Dec 19, 2013 12:49 AM UTC

Show us an example of the output you are getting and include the value of the 'Product' field.

'prod1' seems like a funny way to determine if a product has a discount.

Translate