Jump to content

If Else Statement Within Table, Possible UL


twilitegxa

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 61
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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]

Link to comment
Share on other sites

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";
}
?>

Link to comment
Share on other sites

<?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";
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>

  ...

 

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.