Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,560
    Thanks
    76
    Thanked 105 Times in 104 Posts

    Alignment when missing values

    Greetings,

    I posted this before, but was never successful, and really didn't give the details needed.

    I have an item structure for things such as ore, money, fish, etc. Each item needs to be under the table heading, such as

    Ore
    Copperdust
    Lavarock
    Meteorite

    and I need 4 rows across of table headings, and the items under them.
    Some items are usable and will have a textbox or select menu, and a button to use them, non-usable items wouldn't have anything just amount and the item name.

    I am running into the problem of the table getting completely messed up when you don't have an item, such as

    PHP Code:
    if ($item1['amount'] > 0) {
    echo 
    '<td>item amount item name</td><td>textbox</td><td>button</td>
    }

    else {
    echo '
    <td></td>;

    So when the item doesn't exist it adds a blank TD tag and messes everything up, I only want to show each item they have, and a break down the line such as

    Fish Ore
    Catfish Copperdust
    Walleye Lavarock
    Salmon Meteorite
    plus adding a 2px border doesn't seem to work using border=1

    Here is the sloppy coding, and screenshot. I just want the tables nice and clean, the alignment better looking. It's too much to display like 100 items on the screen at once.

    PHP Code:
    $page .= 'Below is your entire inventory, you may use the usable items, and hold onto or sell the rest.<br /><br />';

            
    $page .= '<table width="90%"><tr><td><b>Herbs</b></td><td></td><td></td><td><b>Fish</b></td><td><b>Currency</b></td></tr><p>';

            
    $page .= '<tr>';

            
    $page .= "<td>(".$item1row['amount'].") Life Herbs</td><td><input type='text' name='item1' size='2' maxlength='4' value=''></td><td><input type='submit' name='item1sub' value='Use'></td>";



            
    $page .= "<td>(".$fish1row['amount'].") Catfish</td>";

          
    $newgold number_format($userrow['gold']);
          
    $page .= "<td>$newgold Gold</td>";
             
    $page .= '</tr>';


            
    $page .= '<tr>';

            
    $page .= "<td>(".$item2row['amount'].") White Nut Herbs</td><td><input type='text' name='item2' size='2' maxlength='4' value=''></td><td><input type='submit' name='item2sub' value='Use'></td>";

            
    $page .= "<td>(".$fish2row['amount'].") Largemouth Bass</td>";

          
    $newbank number_format($userrow['bank']);
          
    $page .= "<td>$newbank Banked Gold</td>";
          
    $page .= '</tr>';

            
    $page .= '<tr>';

            
    $page .= "<td>(".$item3row['amount'].") Chocolate Leaves</td><td><input type='text' name='item3' size='2' maxlength='4' value=''></td><td><input type='submit' name='item3sub' value='Use'></td>";
            
    $page .= "<td>(".$fish3row['amount'].") Northern Pike</td>";

          
    $newsilver number_format($userrow['silvercoins']);
          
    $page .= "<td>$newsilver Silver Coins</td>";
          
    $page .= '</tr>';
          
          
    $page .= '<tr>';

            
    $page .= "<td>(".$item4row['amount'].") Mint Berries</td><td><input type='text' name='item4' size='2' maxlength='4' value=''></td><td><input type='submit' name='item4sub' value='Use'></td>";

            
    $page .= "<td>(".$fish4row['amount'].") Walleye</td>";

            
    $newdragon number_format($userrow['coins']);
          
    $page .= "<td>$newdragon Dragon Coins</td>";

          
    $page .= '</tr>';
          
          
          
    $page .= '<tr>';

            
    $page .= "<td>(".$item5row['amount'].") Rainbow Herbs</td><td><input type='text' name='item5' size='2' maxlength='4' value=''></td><td><input type='submit' name='item5sub' value='Use'></td>";

            
    $page .= "<td>(".$fish5row['amount'].") Salmon</td>";
                
    $newcrystals number_format($userrow['crystals']);
          
    $page .= "<td>$newcrystals Crystals</td>";
          
    $page .= '</tr>';
          

            
    $page .= "<tr><td>(".$item6row['amount'].") Cat Tail Roots</td><td><input type='text' name='item6' size='2' maxlength='4' value=''></td><td><input type='submit' name='item6sub' value='Use'></td></tr>";

            
    $page .= "<tr><td>(".$item7row['amount'].") Beo Leaves</td><td><input type='text' name='item7' size='2' maxlength='4' value=''></td><td><input type='submit' name='item7sub' value='Use'></td></tr>";

            
    $page .= "<tr><td>(".$item8row['amount'].") Rose Berries</td><td><input type='text' name='item8' size='2' maxlength='4' value=''></td><td><input type='submit' name='item8sub' value='Use'></td></tr>";

            
    $page .= '<tr><td><b>Special</b></td><td></td><td></td><td><b>Ore</b></td></tr>';
            
    $page .= '<tr>';
            
    $page .= "<td>(".$spec1row['amount'].") Moonstone Leaf</td><td><input type='text' name='spec1' size='2' maxlength='4' value=''></td><td><input type='submit' name='spec1sub' value='Use'></td>";
            
    $page .= "<td>(".$ore1row['amount'].") Copperdust</td>";
            
    $page .= '</tr>';
            
            
    $page .= '<tr>';
            
    $page .= "<td>(".$spec2row['amount'].") Firefly Light</td><td><input type='text' name='spec2' size='2' maxlength='4' value=''></td><td><input type='submit' name='spec2sub' value='Use'></td>";
             
    $page .= "<td>(".$ore2row['amount'].") Lavarock</td>";
            
    $page .= '</tr>';
            
            
    $page .= '<tr>';
            
    $page .= "<td></td><td></td><td></td>";
             
    $page .= "<td>(".$ore3row['amount'].") Blue Ore</td>";
            
    $page .= '</tr>';

            
    $page .= '</table>'
    Attached Thumbnails Attached Thumbnails Alignment when missing values-inven.jpg  

  • #2
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,487
    Thanks
    279
    Thanked 32 Times in 31 Posts
    this might be more if a style issue than a php issue, there are some css style attributes that can help you here such as possibly table-layout:fixed; or using some inherit attributes on some of the styles.

    you might really consider asking over in the css area. Just my take on it.

    Typically what happens is that when you put together the colums and rows you need to specify a width for them, that way if there is no data that cell is still the same width regardless, i always use % rather than px value to allow for dif screen resolutions.

    Good luck with your project
    Last edited by durangod; 07-07-2011 at 06:33 PM.

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    Anytime you use an if statement whose output is a row of html with the data be sure that you output the entire row, using a qualifier of quantity would mean you dont want to show that item if there isnt a quantity. If that isnt the case you will just want to post the items and quantity whether they are zero or not.
    If you can't stand behind your troops, feel free to stand in front of them
    Semper Fidelis

  • #4
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,560
    Thanks
    76
    Thanked 105 Times in 104 Posts
    Yeah I don't want the item to exist if they don't have any of that item. But I am afraid this will happen.

    Ore
    (192) Copperdust

    (84) Meteorite
    (102) Royal

    (24) Giant

    where there are spaces left when they don't have the item.

  • #5
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    It is hard to understand what you are looking for. What I would do is take each item category and run a separate query where the quantity is not zero, then create a table to show each of the items. Once you have all the tables then position them inside a master table to align them the way you want.
    If you can't stand behind your troops, feel free to stand in front of them
    Semper Fidelis

  • #6
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,560
    Thanks
    76
    Thanked 105 Times in 104 Posts
    That could turn out to be a 3,000 line script. I thought about doing a foreach or something

  • #7
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    You can if you have the expertise, you can load the data into arrays and use a foreach within the table you just need to know how to create and grab the form variables afterward to use the data.
    If you can't stand behind your troops, feel free to stand in front of them
    Semper Fidelis

  • #8
    Senior Coder
    Join Date
    Apr 2010
    Posts
    1,560
    Thanks
    76
    Thanked 105 Times in 104 Posts
    What about something like this?

    PHP Code:
    <td>
    if (
    $itemrow['amount'] > 0) {
    Item 1<br />
    }
    if (
    $itemrow2['amount'] > 0) {
    Item 2<br />
    }
    if (
    $itemrow3['amount'] > 0) {
    Item 3<br />

    Would something like that work using a break?


  •  

    Posting Permissions

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