twilitegxa Posted September 18, 2008 Share Posted September 18, 2008 Here is my page: http://www.webdesignsbyliz.com/sailormoonrpg/test.php The table on the right at the bottom is the table in question. I want the data displayed to look like this: [table width=430" border="0] [td width=284][strong]Attribute/Sub-Attribute[/strong] [td width=59][strong]Level[/strong][/td][/tr][/table] [td width=73][strong]Points[/strong][/td] [/tr] Scout Powers 5 20 Animal Guardian 4 4 Item Of Power - Upgraded Sailor Suit 1 2 [/table] The first item in the ul list should be Scout Power in this case. The next section (attribute_id) would be indented some, then the next part (desc) would be indented more with a - before it starts. Does this make sense? I can give an example of how I want the entire table to look as well. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 18, 2008 Author Share Posted September 18, 2008 Here is the whole table, roughly. [table cellspacing=0" cellpadding="0] [td colspan=3][strong]Character Attributes and Sub-Attributes[/strong] [strong]Attribute/Sub-Attribute[/strong] [strong]Level[/strong] [/td] [strong]Points[/strong] Scout Powers [td align=middle]5 [/td] [/tr][/table] [td align=middle]20 [/tr] Animal Guardian[/table] [td align=middle]4[/td] [/td] [/tr][/table] [td align=middle]4 [/tr] Combined Attacks1[/table] [td align=middle]4[/td] [/td] [/tr][/table] [td align=middle]4 [/tr] Elemental Control2[/table] [td align=middle]4[/td] [/td] [/tr][/table] [td align=middle]12 [/tr] Item of Power -Upgraded Sailor Fuku (Suit)[/table] [td align=middle]1[/td] [/td] [/tr][/table] [td align=middle]2 [/tr] -Moon Tiara[/table] [td align=middle]1[/td] [/td] [/tr][/table] [td align=middle]2 [/tr] -Luna Pen[/table] [td align=middle]1[/td] [/td] [/tr][/table] [td align=middle]2 [/tr] -Crescent Moon Wand[/table] [td align=middle]1[/td] [/td] [/tr][/table] [td align=middle]2 [/tr] -Imperium Silver Crystal[/table] [td align=middle]5[/td] [/td] [/tr][/table] [td align=middle]10 [/tr] Rejuvenation[/table] [td align=middle]5[/td] [/td] [/tr][/table] [td align=middle]5 [/tr] Sailor Scout Attack[/table] [td align=middle][/td] [/td] [/tr][/table] [td align=middle] [/tr] -Moon Crystal Healing Activation[/table] [td align=middle]4[/td] [/td] [/tr][/table] [td align=middle]16 [/tr] -Moon Scepter Elimination[/table] [td align=middle]4[/td] [/td] [/tr][/table] [td align=middle]2 [/tr] -Cosmic Moon Power[/table] [td align=middle]3[/td] [/td] [/tr][/table] [td align=middle]1 [/tr] -Moon Healing Activation[/table] [td align=middle]2[/td] [/td] [/tr][/table] [td align=middle]1 [/tr] -Moon Tiara Magic[/table] [td align=middle]2[/td] [/td] [/tr][/table] [td align=middle]1 [/tr] Acrobatics3[/table] [td align=middle]1[/td] [/td] [/tr][/table] [td align=middle]1 [/tr] Appearance[/table] [td align=middle]4[/td] [/td] [/tr][/table] [td align=middle]4 [/tr] Art of Distraction[/table] [td align=middle]4[/td] [/td] [/tr][/table] [td align=middle]3 [/tr] Combat Mastery[/table] [td align=middle]2[/td] [/td] [/tr][/table] [td align=middle]4 [/tr] Energy Bonus[/table] [td align=middle]6[/td] [/td] [/tr][/table] [td align=middle]6 [/tr] Focused Combat (Sailor Scout Attack)[/table] [td align=middle]3[/td] [/td] [/tr][/table] [td align=middle]3 [/tr] Heightened Scout Power[/table] [td align=middle]7[/td] [/td] [/tr][/table] [td align=middle]7 [/tr] Strong Soul[/table] [td align=middle]3[/td] [/td] [/tr][/table] [td align=middle]3 [/tr] [/table] Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 Sorry, I thought the code should show the table. Here is a link to an old page I create with just HTML, but you can get the idea of how I want the table to look: http://twilitegxa.tripod.com/Profiles/SailorMoon2.html Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 OK, I kinda see what you want now, but how do you know which ones need to be indented? Do you only want the ones with "Item Of Power" indented? If so, replace that while statement with this one: <?php while($row = mysql_fetch_array( $result )) { if ($row['attribute_id']=="Item Of Power"){ if ($count==0){ echo "<tr><td colspan='7'>Item Of Power</td></tr>\n"; $count = 1; } echo "<tr><td> - \n"; } else{ echo "<tr><td>\n"; echo $row['attribute_id']; echo " "; } echo $row['desc']; echo "</td><td width='2%'> </td><td width='1%' align='right'>\n"; echo $row['level']; echo "</td><td width='2%'> </td><td width='2%'> </td><td width='1%' align='right'>\n"; echo $row['points']; echo "</td><td width='2%'> </td></tr>\n"; } ?> Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 OOOOHHH, I think I just realized what you're trying to do... Give me a min... Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 <?php $attribute_id = ""; while($row = mysql_fetch_array( $result )) { if ($row['attribute_id']!=$attribute_id){ echo "<tr><td colspan='7'>$attribute_id</td></tr>\n"; $attribute_id = $row['attribute_id']; } echo "<tr><td> - \n"; echo $row['desc']; echo "</td><td width='2%'> </td><td width='1%' align='right'>\n"; echo $row['level']; echo "</td><td width='2%'> </td><td width='2%'> </td><td width='1%' align='right'>\n"; echo $row['points']; echo "</td><td width='2%'> </td></tr>\n"; } ?> Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 First of all, Scout Power is not indented, then next to be indented from Scout Power are the entries of Animal Guardian, Combined Attacks, Elemental Control, Item Of Power, Rejuvenation, and Sailor Scout Attack. Then from those, there needs to be anoter indent for all of the Item Of Power terms and also the same indent for all the Sailor Scout Attack terms. See what I'm saying? I think it's going to be hard to do. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 That last post you posted, is that the whole thing? It seems like there would be more for all of what I want to do, but I wanted to check. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 I just modified my code. Do you want the attribute_id as a sort of mini-header, and each item under a unique attribute_id to be indented? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 The other problem is that some of the entries in the table have a blank value for the desc, so if we put a - in front of it, some of the rows will show a - that don't need to. Is there a way to modify my table in my database so that if no value is entered into the desc field that it doesn't display a blank space? I think it is set to not null right now. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 Yes, but it would be easier to just do it in the PHP code. What do you want in those cases? Type out each scenario in plain text here. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 That sounds about right. For this particular example, the only attibute_id that would be indented is Scout Powers, then the other attribute_id's are indented until it gets to Acrobatics and then ones after it. I have a table that lists al the attributes, by category, but I don't know how to pull the information from it properly. I have scout_knight_subattributes with the terms: scout/knight power, Animal Guardian Combined Attacks Elemental Control Emotional Control Item Of Power Knight Attack Rejuvenation Sailor Scout Attack Then negaverse_dark_subattributes with: negaverse/dark power Energy Drain Environmental Control Mind Control Negaverse Attack Negaverse Item Negaverse Magic Positive Energy Deflection Summon/Control Servant and neutral_attributes with: Acrobatics Appearance Art Of Distraction Combat Mastery Damn Healthy! Divine Realtionship Energy Bonus Extra Attacks Focused Combat Fortified Body Heightened Negaverse Power Heightened Senses Heightened Scout Powers Massive Damage Powerful Mind Special Attack/Defense Speed Strong Soul Supernatural Training Unique Character Attribute I just have a table that those tables we are working with it pulling from right now that lists the identity, attribute_id, level, and points Maybe I could use the other tables to specifiy the terms so we can align them the way I want them? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 What do you mean what do I want in those cases? In the cases that the user enters a blank value, I just don't want it to display anything and then I want it to display if there is a value. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 Did I confuse you? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 Sorry, went to dinner. Looking now... Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 OK, you did confuse me. write it out in a fake if/else statement like this: if the attribute_id is <whatever>, do <something> else if the attribute_id is <whateverelse>, do <somethingelse> and you can nest them, if necessary, like: if the attribute_id is <whatever>, do <something> else do this if statement: if the <some other key> is <whatever>, do <something> else if the attribute_id is <whateverelse>, do <somethingelse> ... Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 Can we try this one step at a time maybe? Like could a statement be written kind of like this: if attribute_id = Scout Powers, display with no indentation if attribute id has a desc field, indent x number of pixels if attribute_id falls under subattributes category, indent x number of pixels I can alter my table somehow to make certain attributes fall into the appropraite categories, if needed. Like for this example, Scout Power, then skipping over the others until it gets to Acrobatics...these are all NOT indented. Then, if the attribute_id is under the Scout Powers attribute, it is indented. Then, if the attribute_id has a desc field, then indent a little more. Does that make any mroe sense? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 Like Scout Powers is an attribute, while the ones listed below it are sub-attributes then the ones starting with Acrobatics are neutral_attributes. I have tables, one listing all neutral_attributes and one listing all scout_knight_subattributes, but what I can do it make the Scout Power attribute be in it's own table named scout_knight_attributes, then all the others would be in scout_knight_subattributes. The table it's pulling from right now is character_attributes. Or I could just alter that table and make an extra field to signify if it's either an attribute or sub-attribute. That would probably be easier. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 OK, that gives me a good starting place. I'll help you more tomorrow. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 Okay, thanks. Talk to you tomorrow. :-) Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 OK, one thing that you should learn about if statements is this: if (conditionA) do actionA if (conditionB) do actionB In this case, these are the possibilities: just actionA, just actionB, both actionA and actionB, or neither actionA or actionB if (conditionA) do actionA elseif (conditionB) do actionB In this case, these are the possibilities: just actionA, just actionB, or neither actionA or actionB if (conditionA) do actionA else do actionB In this case, these are the possibilities: just actionA, or just actionB if (conditionA AND NOT conditionB) do actionA elseif (NOT conditionA AND conditionB) do actionB In this case, these are the possibilities: just actionA, just actionB, or neither actionA or actionB Hopefully that helps you with learning if statements. So, on to your code. Working with the same section with the while statement: <?php while($row = mysql_fetch_array( $result )) { if ($row['attribute_id']=="Scout Powers"){ echo "<tr><td>\n"; echo $row['attribute_id']; echo " "; echo $row['desc']; } elseif ($row['desc']!=""){ echo "<tr><td> \n"; //indent two spaces echo $row['attribute_id']; echo " "; echo $row['desc']; } elseif ($row['attribute_id']="?"){ //not sure how to detect its subattributes, so you'll have to do that echo "<tr><td> \n"; //indent four spaces echo $row['attribute_id']; echo " "; echo $row['desc']; } else{ //this is the defeault echo "<tr><td> \n"; //indent six spaces echo $row['attribute_id']; echo " "; echo $row['desc']; } echo "</td><td width='2%'> </td><td width='1%' align='right'>\n"; echo $row['level']; echo "</td><td width='2%'> </td><td width='2%'> </td><td width='1%' align='right'>\n"; echo $row['points']; echo "</td><td width='2%'> </td></tr>\n"; } ?> Are we getting anywhere? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 There was an error: Parse error: syntax error, unexpected $end in on line 211 Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 That's because my code wasn't complete, and I had a typo. Both in this line: elseif ($row['attribute_id']="?"){ //not sure how to detect its subattributes, so you'll have to do that needs to have two "==" and you need to fill in the "?". Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted September 19, 2008 Author Share Posted September 19, 2008 Okay, I made a field in the table that is equal to 1 if the attribute_id is a sub-attribute and the field is named 'sub'. How would I write that in for the ? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 19, 2008 Share Posted September 19, 2008 I don't know what your new field name is, so I'll say it's "field_name." elseif ($row['field_name']==1){ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.