Results 1 to 10 of 10

Thread: How to hide entry when value is 0

  1. #1
    Join Date
    Dec 2009
    Posts
    48
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default How to hide entry when value is 0

    Hello,

    I have some numbers in two of my columns of my database. Sometimes, this number is set, sometimes, this number is 0. When it's 0, I'd like to hide it, make sure that it's not displayed.

    Here's my current code: (part of it)

    PHP Code:
    <?php

    while($item=mysql_fetch_array($finalQuery)){
              
    $base_m=5;
              
    $item['col1'] = round ((($item['col1']+5) *1.85),0); $item['col01'] = $base_m*(ceil(($item['col1'])/$base_m));
              
    $item['col2'] = round ((($item['col2']+5) *1.85),0); $item['col02'] = $base_m*(ceil(($item['col2'])/$base_m));
    >?

    <
    td width="50%" align="center"><h4><?php echo "{$item['col01']}?></h4></td>
    <td width="
    50%" align="center"><h4><?php echo "{$item['col02']}?></h4></td>
    If both columns are filled with numbers, the math function is added and the numbers are filled perfectly in the table.

    However, if one of those numbers is 0, the math function is added and the number turns to 10. I'd like to hide this. Or even all entries that gives a 0, so the math function wouldn't even be calculated at all... In either way, it cannot be shown in the table.

    I tried adding it in the select query (where value > 0), but that doesn't work and returns no results at all (nothing, not even other results I'm trying to get after this part of cod). I also tried to use something like "if ($item['col1'] > 0)", but it gives me an error... or executes fine when there's no 0, when there is a 0, I see nothing.....can't get it right.

    Does anybody have any idea's?
    Last edited by Bar2aYunie; 06-26-2010 at 06:55 PM.

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Was the select you tried was something like

    Select value1 from number_table where value1 > 0

    and is the value1 saved as an int or numeral and not a string?
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Dec 2009
    Posts
    48
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Yeah, and it is saved as float. Since I have to calculate with these numbers.... But I also got two more variables (which have nothing to do with this question though) in my select WHERE query. So maybe that's messing each other up?

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    It should still be able to distinguish.

    Can you post your select and/or is it the same result when you trigger the select from the DB and from the php?
    Corrections to my coding/thoughts welcome.

  5. #5
    Join Date
    Dec 2009
    Posts
    48
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Sure, though I don't have the values in the select function, since that doesn't work.... (though it works in the db)

    PHP Code:
    SELECT FROM `FoldersWHERE `sizecat`='{$sizecat}' AND `finalsize`='{$finalsize}' AND `color`='{$color}'  AND `material`='{$material}' AND `totalsize`='{$totalsize}';") 
    If I would put it in, I'd put it in like this:

    PHP Code:
    SELECT FROM `FoldersWHERE `sizecat`='{$sizecat}' AND `finalsize`='{$finalsize}' AND `color`='{$color}'  AND `material`='{$material}' AND `totalsize`='{$totalsize}' AND `price1` > '0';") 

  6. #6
    Join Date
    Dec 2009
    Posts
    48
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Solved!

    Okay, maybe this isn't the best or most practical or nicest solution, but at least it works and at least I have a solution. Lateron, I'm gonna work on improving the whole code and I'll keep looking for the best solution.

    For now, I just wanted to share the solution with you ^.^

    PHP Code:
    <?php 

    while($item=mysql_fetch_array($finalQuery)){ 
              
    $base_m=5
              if (
    $item['col1'] > "0") {$item['col1'] = round ((($item['col1']+5) *1.85),0); $item['col01'] = $base_m*(ceil(($item['col1'])/$base_m)); }
              if (
    $item['col2'] > "0") {$item['col2'] = round ((($item['col2']+5) *1.85),0); $item['col02'] = $base_m*(ceil(($item['col2'])/$base_m)); }
    >? 
    // if you want, you can add what it should display by using the else statement. In this case, it just doesn't display anything
    <td width="50%" align="center"><h4><?php echo "{$item['col01']}?></h4></td> 
    <td width="
    50%" align="center"><h4><?php echo "{$item['col02']}?></h4></td>
    Thx for trying to help. And if anybody have any other suggestions, lemme know!

  7. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Your closing PHP tag is inverted. It should be ?> not >?
    Corrections to my coding/thoughts welcome.

  8. #8
    Join Date
    Dec 2009
    Posts
    48
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    yeah of course, typo, lol

  9. #9
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    If you want to hide entry when value is 0, you will use dock icon.
    In order to get rid of the dock icon, you must modify the file named 'Info.plist' inside the Application's package (i.e. Sherlock.app/Contents/Info.plist). Open this file in your favorite text editor and add the following section (if it's already present simply change the 0 to a 1 in the string tag:

    [KEY]NSUIElement[/KEY]
    [STRING]1[/STRING]

  10. #10
    Join Date
    Dec 2009
    Posts
    48
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    That doesn't look like php..... I'm not sure what you are saying...

Bookmarks

Posting Permissions

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