Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-07-2011, 03:34 PM   PM User | #1
myfayt
Senior Coder

 
Join Date: Apr 2010
Posts: 1,156
Thanks: 46
Thanked 95 Times in 94 Posts
myfayt can only hope to improve
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

Quote:
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
Click image for larger version

Name:	inven.jpg
Views:	20
Size:	27.1 KB
ID:	10032  
myfayt is offline   Reply With Quote
Old 07-07-2011, 05:24 PM   PM User | #2
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
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 05:33 PM..
durangod is offline   Reply With Quote
Old 07-07-2011, 06:07 PM   PM User | #3
jimhill
Regular Coder

 
Join Date: Jul 2010
Posts: 271
Thanks: 3
Thanked 40 Times in 40 Posts
jimhill is an unknown quantity at this point
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
jimhill is offline   Reply With Quote
Old 07-07-2011, 06:31 PM   PM User | #4
myfayt
Senior Coder

 
Join Date: Apr 2010
Posts: 1,156
Thanks: 46
Thanked 95 Times in 94 Posts
myfayt can only hope to improve
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.
myfayt is offline   Reply With Quote
Old 07-07-2011, 09:54 PM   PM User | #5
jimhill
Regular Coder

 
Join Date: Jul 2010
Posts: 271
Thanks: 3
Thanked 40 Times in 40 Posts
jimhill is an unknown quantity at this point
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
jimhill is offline   Reply With Quote
Old 07-07-2011, 11:31 PM   PM User | #6
myfayt
Senior Coder

 
Join Date: Apr 2010
Posts: 1,156
Thanks: 46
Thanked 95 Times in 94 Posts
myfayt can only hope to improve
That could turn out to be a 3,000 line script. I thought about doing a foreach or something
myfayt is offline   Reply With Quote
Old 07-07-2011, 11:53 PM   PM User | #7
jimhill
Regular Coder

 
Join Date: Jul 2010
Posts: 271
Thanks: 3
Thanked 40 Times in 40 Posts
jimhill is an unknown quantity at this point
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
jimhill is offline   Reply With Quote
Old 07-08-2011, 12:52 PM   PM User | #8
myfayt
Senior Coder

 
Join Date: Apr 2010
Posts: 1,156
Thanks: 46
Thanked 95 Times in 94 Posts
myfayt can only hope to improve
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?
myfayt is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:05 AM.


Advertisement
Log in to turn off these ads.