Results 1 to 12 of 12
  1. #1
    Internet Cowboy
    Join Date
    January 18th, 2005
    Posts
    4,662
    Need help with PHP
    Hi,

    I am hoping that someone can offer me a remedy to a problem I have. My PHP knowledge is limited and I am trying to do what I think is a basic function, but just can't seem to get it right.

    Below is a section of the script I am using. What I am trying to do is display a field on the web page that subtracts 'Our Price' from 'Retail'.
    Here is a copy of the script:

    while ($line = mysql_fetch_assoc($result)) {
    $TableLine1 = $line["buylink"];
    $TableLine2 = $line["model"];
    $TableLine3 = $line["subcat"];
    $TableLine4 = $line["brand"];
    $TableLine5 = $line["price"];
    $TableLine6 = $line["Item"];
    $TableLine7 = $line["desc"];
    $TableLine8 = $line["bigpic"];
    $TableLine9 = $line["smallpic"];
    $TableLine10 = $line["info1"];
    $TableLine11 = $line["info2"];
    $TableLine12 = $line["info3"];
    $TableLine13 = $line["category"];
    $TableLine14 = $line["catthree"];
    $TableLine15 = $line["retail"];
    $TableLine16 = $line["unitofmeasure"];
    $TableLine17 = $line["mfrlogo"];
    $TableLine18 = $line["itemcode"];
    // Add lines here with more field and variable names


    echo "<tr><td width=20%><img src='$TableLine9' alt='$TableLine6 by $TableLine4' border='0'></td><td align=left width=60%><b>$TableLine4</b> - <a href='$TableLine1' title='$TableLine6 by $TableLine4'>$TableLine6</a><br>Retail: $TableLine15 --- <b>Our Price: $TableLine5</b> You Save: ?????????</td><td align=center width=20%><a href='$TableLine1' title='$TableLine6 by $TableLine4'><img src='/images/moreinfo.jpg' border='0' alt='More Information on $TableLine6'</a></td></tr><tr><td colspan='3'><hr width=\"100%\" align=\"left\"></td></tr>";

    Retail price is defined as $TableLine15
    Selling Price is defined as $TableLine5

    How do I get it to display the difference of these two where it says 'You Save: ' ?

    Thank you for your help in advance.

    Scott
    Last edited by UncleScooter; February 5th, 2005 at 12:19 PM. Reason: forgot to mark the part of the script where I need help


  2. #2
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    Right before your echo statement add something like this:

    $Savings = $TableLine15 - $TableLine5;

    Then just use $Savings as your variable. It's as simple as that

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  3. #3
    Internet Cowboy
    Join Date
    January 18th, 2005
    Posts
    4,662
    Thanks Scott,
    I tried that last night, and again just now and I get:

    "You Save: 0"

    while ($line = mysql_fetch_assoc($result)) {
    $TableLine1 = $line["buylink"];
    $TableLine2 = $line["model"];
    $TableLine3 = $line["subcat"];
    $TableLine4 = $line["brand"];
    $TableLine5 = $line["price"];
    $TableLine6 = $line["Item"];
    $TableLine7 = $line["desc"];
    $TableLine8 = $line["bigpic"];
    $TableLine9 = $line["smallpic"];
    $TableLine10 = $line["info1"];
    $TableLine11 = $line["info2"];
    $TableLine12 = $line["info3"];
    $TableLine13 = $line["category"];
    $TableLine14 = $line["catthree"];
    $TableLine15 = $line["retail"];
    $TableLine16 = $line["unitofmeasure"];
    $TableLine17 = $line["mfrlogo"];
    $TableLine18 = $line["itemcode"];
    // Add lines here with more field and variable names

    $Savings = $TableLine15 - $TableLine5;
    echo "<tr><td width=20%><img src='$TableLine9' alt='$TableLine6 by $TableLine4' border='0'></td><td align=left width=60%><b>$TableLine4</b> - <a href='$TableLine1' title='$TableLine6 by $TableLine4'>$TableLine6</a><br>Retail: $TableLine15 --- <b>Our Price: $TableLine5</b> You Save: $Savings </td><td align=center width=20%><a href='$TableLine1' title='$TableLine6 by $TableLine4'><img src='/images/moreinfo.jpg' border='0' alt='More Information on $TableLine6'</a></td></tr><tr><td colspan='3'><hr width=\"100%\" align=\"left\"></td></tr>";



    BTW...nice name


  4. #4
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    Did you make sure the retail and sale prices are both set? Sometimes a datafeed is missing one or the other. There's really no reason why the value should be 0 unless it actually is 0. I usually check if it's 0 before I print a sale price. That way if there isn't a sale price, I don't indicate that there is one. It just shows the retail price ignoring any savings.

    Nice name yourself
    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  5. #5
    Internet Cowboy
    Join Date
    January 18th, 2005
    Posts
    4,662
    Every item has a retail price and a sale price.
    Both are showing on the page.
    I am puzzled.


  6. #6
    Fear and Arrogance jrrl's Avatar
    Join Date
    January 18th, 2005
    Location
    Pittsburgh
    Posts
    485
    Just a guess here.

    Try:

    $Savings = str_replace('$','',$TableLine15) - str_replace('$','',$TableLine5);

    If you have dollar sign characters in the strings, PHP won't reinterpret them as numbers correctly.

    -John.
    There's a reason army's wear uniforms even though it makes them easier to spot. Sometimes that's what you want. Uniforms suggest organization, power, and numbers. These, in turn, inspire fear. And, as any good operative knows, there is no more effective weapon than fear.

    Hosting Comparison - HostScope - jrrl.com

  7. #7
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    That's strange.. Maybe try this:

    $Savings = round(($TableLine15 - $TableLine5), 2);

    That's usually better anyway because it'll force 2 decimals.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  8. #8
    Not Verif-Lidated infoTim's Avatar
    Join Date
    January 18th, 2005
    Location
    Sunny Florida
    Posts
    1,021
    If the prices have a "$" in it from the feed, that would make PHP return "0" for the arithmetic.
    Tim
    consultant by day, affiliate by night

  9. #9
    ABW Ambassador sjangro's Avatar
    Join Date
    January 18th, 2005
    Location
    Boston
    Posts
    1,529
    Do your prices in the database have currency symbols in them? Looks like PHP may be treating them as string types.

  10. #10
    Internet Cowboy
    Join Date
    January 18th, 2005
    Posts
    4,662
    I have just removed the $ sign in the feed and will add it to the display. I am uploading the script now. BRB with info.


  11. #11
    Internet Cowboy
    Join Date
    January 18th, 2005
    Posts
    4,662
    That did it. Apparently the $ sign is a problem.
    Thank you all for your help!!


  12. #12
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    Awesome, didn't even think about that!
    Hatred stirs up strife, But love covers all transgressions.

  13. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. PHP question - include(file.php) with variables
    By teezone in forum Programming / Datafeeds / Tools
    Replies: 8
    Last Post: September 4th, 2009, 04:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •