Jump to content

If Else Statement Within Table, Possible UL


twilitegxa

Recommended Posts

  • Replies 61
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Here is the full code I have, just in case I've messed up somewhere, so you can see:

 

<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="simpletree2.css" />
</head>

<?php
$con = mysql_connect("mysql5.webdesignsbyliz.com","twilitegxa","minimoon");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("smrpg", $con);
  
//get Sailor Moon's data from the "scout" table
$result = mysql_query("SELECT * FROM scout where identity = 'Sailor Moon'") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
$birthdatemonth = $row["birthdatemonth"];
$birthdateday = $row["birthdateday"];
$birthdateyear = $row["birthdateyear"];
$birthdate = $birthdatemonth . " " . $birthdateday . ", ". $birthdateyear;
$identity = $row["identity"];

echo "<h1><center>$identity</center></h1>";
echo "<table border='0' width='100%'>";
// keeps getting the next row until there are no more to get
echo "<tr><td width='25%'>"; 
	echo "<b>Name:</b></td><td>"; 
echo $row['charactername'];
        echo "</td></tr><tr><td>"; 
	echo "<b>Element Of Influence:</b></td><td>";
echo $row['elementofinfluence'];
        echo "</td></tr><tr><td>"; 
	echo "<b>Age:</b></td><td>";
echo $row['age'];
        echo "</td></tr><tr><td>";
    echo "<b>Birthdate:</b></td><td>";
echo $birthdate;
echo "</td></tr><tr><td>";  
    echo "<b>Height:</b></td><td>"; 
echo $row['heightfeet'];
echo "&#39; " ;
echo $row['heightinches'];
echo "&#34;";
        echo "</td></tr><tr><td>"; 
    echo "<b>Blood Type:</b></td><td>"; 
echo $row['bloodtype'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Hobbies:</b></td><td>"; 
echo $row['hobbies'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite Color:</b></td><td>"; 
echo $row['favoritecolor'];
        echo "</td></tr><tr><td>";   
    echo "<b>Favorite Gemstone:</b></td><td>"; 
echo $row['favoritegemstone'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite Food:</b></td><td>"; 
echo $row['favoritefood'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Least Favorite Food:</b></td><td>"; 
echo $row['leastfavoritefood'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite School Subject:</b></td><td>"; 
echo $row['favoriteschoolsubject'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Least Favorite School Subject:</b></td><td>"; 
echo $row['leastfavoriteschoolsubject'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Strengths:</b></td><td>"; 
echo $row['strengths'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Weaknesses:</b></td><td>"; 
echo $row['weaknesses'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Goal:</b></td><td>"; 
echo $row['goal'];
echo "...";
        echo "</td></tr></table><p>";  
echo $row['biography'];
        echo "</p>"; 
        
echo "</td></tr>"; 
echo "<tr><td> </td></tr>";

echo "</table>";

$result = mysql_query("SELECT * FROM stats where identity = 'Sailor Moon'") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
echo "<table width='100%' valign='top'><tr><td width='50%' align='right' valign='top'>\n"; // added align='right' valign='top'
echo "<table width='100%' border='0' id='stats' align='right'>\n";
// keeps getting the next row until there are no more to get
echo "<tr><td colspan='3' id='th'>Stats And Derived Values</td></tr>\n";
echo "<tr><td>\n"; 
	echo "<b>Body:</b></td><td col class='right'>\n"; 
	echo $row['body'];
echo "</td></tr><tr><td>\n"; 
	echo "<b>Mind:</b></td><td col class='right'>\n";
	echo $row['mind'];
echo "</td></tr><tr><td>\n"; 
	echo "<b>Soul:</b></td><td col class='right'>\n";
	echo $row['soul'];
echo "</td></tr><tr><td>\n";
	echo " </td></tr><tr><td>\n";
	echo "<b>Health Points:</b></td><td col class='right'>\n"; 
	echo $row['health'];
echo "</td></tr><tr><td>\n"; 
	echo "<b>Energy Points:</b></td><td col class='right'>\n"; 
	echo $row['energy'];
echo "</td></tr><tr><td>\n"; 
	echo "<b>Attack Combat Value:</b></td><td col class='right'>\n"; 
	echo $row['acv'];
echo "</td><td col class='right'>\n"; // added </td>
	echo " (";
	echo $row['acv_sa'];
	echo " for Sailor Scout Attack)";
echo "</td>\n";
echo "</td></tr><tr><td >\n"; 
	echo "<b>Defense Combat Value:</b></td><td col class='right'>\n"; 
	echo $row['dcv'];
echo "</td><td col class='right'>\n"; // added </td>
	echo " (";
	echo $row['dcv_sa'];
	echo " for Sailor Scout Attack)";
//echo "</td>\n"; // that's an extra one
echo "</td></tr><tr><td>\n";   
	echo "<b>Total Character Points:</b></td><td col class='right'>\n"; 
	echo $row['tcp'];
echo "</td></tr>\n"; 
echo "</table>\n";

//while statement for character_attributes

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['sub']==1){ //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";

//end while statement

$result = mysql_query("SELECT * FROM character_attributes ORDER BY attribute_id ASC") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
echo "</td><td valign='top' width='50%' rowspan='2'>\n"; // added this whole line
echo "<table width='100%' border='0' id='stats' align='left'>\n";
echo "<tr><td colspan='7' id='th'>Character Attributes And Sub-Attributes</td></tr>\n";
echo "<tr class='sub'><td>Attribute/Sub-Attribute</td><td colspan='3' align='center'>Level</td><td colspan='3' align='center'>Points</td></tr>\n";
echo "<tr><td></td></tr>\n";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	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";
}
echo "</table></td></tr><tr><td valign='top' width='50%'>\n";		
$result = mysql_query("SELECT * FROM character_defects where identity = 'Sailor Moon' ORDER BY defect_id ASC") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
echo "<table border='0' width='100%' id='stats' align='right'>\n";
echo "<tr><td colspan='3' id='th'>Character Defects</td></tr>\n";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	echo "<tr><td>\n"; 
		echo $row['defect_id'];
		echo " ";
		echo $row['desc'];
	echo "</td><td>\n";
		echo $row['bp'];
		echo " BP";
	echo "</td></tr>\n";
}
echo "</table>\n";
echo "</td><td>\n";		
echo "</td></tr></table>\n";

 

And the error would be line 207. I had some extra blank lines before.

Link to comment
Share on other sites

Line 165 needed a }.

 

<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="simpletree2.css" />
</head>

<?php
$con = mysql_connect("mysql5.webdesignsbyliz.com","twilitegxa","minimoon");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("smrpg", $con);
  
//get Sailor Moon's data from the "scout" table
$result = mysql_query("SELECT * FROM scout where identity = 'Sailor Moon'") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
$birthdatemonth = $row["birthdatemonth"];
$birthdateday = $row["birthdateday"];
$birthdateyear = $row["birthdateyear"];
$birthdate = $birthdatemonth . " " . $birthdateday . ", ". $birthdateyear;
$identity = $row["identity"];

echo "<h1><center>$identity</center></h1>";
echo "<table border='0' width='100%'>";
// keeps getting the next row until there are no more to get
echo "<tr><td width='25%'>"; 
	echo "<b>Name:</b></td><td>"; 
echo $row['charactername'];
        echo "</td></tr><tr><td>"; 
	echo "<b>Element Of Influence:</b></td><td>";
echo $row['elementofinfluence'];
        echo "</td></tr><tr><td>"; 
	echo "<b>Age:</b></td><td>";
echo $row['age'];
        echo "</td></tr><tr><td>";
    echo "<b>Birthdate:</b></td><td>";
echo $birthdate;
echo "</td></tr><tr><td>";  
    echo "<b>Height:</b></td><td>"; 
echo $row['heightfeet'];
echo "&#38;#39; " ;
echo $row['heightinches'];
echo "&#38;#34;";
        echo "</td></tr><tr><td>"; 
    echo "<b>Blood Type:</b></td><td>"; 
echo $row['bloodtype'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Hobbies:</b></td><td>"; 
echo $row['hobbies'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite Color:</b></td><td>"; 
echo $row['favoritecolor'];
        echo "</td></tr><tr><td>";   
    echo "<b>Favorite Gemstone:</b></td><td>"; 
echo $row['favoritegemstone'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite Food:</b></td><td>"; 
echo $row['favoritefood'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Least Favorite Food:</b></td><td>"; 
echo $row['leastfavoritefood'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite School Subject:</b></td><td>"; 
echo $row['favoriteschoolsubject'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Least Favorite School Subject:</b></td><td>"; 
echo $row['leastfavoriteschoolsubject'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Strengths:</b></td><td>"; 
echo $row['strengths'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Weaknesses:</b></td><td>"; 
echo $row['weaknesses'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Goal:</b></td><td>"; 
echo $row['goal'];
echo "...";
        echo "</td></tr></table><p>";  
echo $row['biography'];
        echo "</p>"; 
        
echo "</td></tr>"; 
echo "<tr><td> </td></tr>";

echo "</table>";

$result = mysql_query("SELECT * FROM stats where identity = 'Sailor Moon'") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
echo "<table width='100%' valign='top'><tr><td width='50%' align='right' valign='top'>\n"; // added align='right' valign='top'
echo "<table width='100%' border='0' id='stats' align='right'>\n";
// keeps getting the next row until there are no more to get
echo "<tr><td colspan='3' id='th'>Stats And Derived Values</td></tr>\n";
echo "<tr><td>\n"; 
	echo "<b>Body:</b></td><td col class='right'>\n"; 
	echo $row['body'];
echo "</td></tr><tr><td>\n"; 
	echo "<b>Mind:</b></td><td col class='right'>\n";
	echo $row['mind'];
echo "</td></tr><tr><td>\n"; 
	echo "<b>Soul:</b></td><td col class='right'>\n";
	echo $row['soul'];
echo "</td></tr><tr><td>\n";
	echo " </td></tr><tr><td>\n";
	echo "<b>Health Points:</b></td><td col class='right'>\n"; 
	echo $row['health'];
echo "</td></tr><tr><td>\n"; 
	echo "<b>Energy Points:</b></td><td col class='right'>\n"; 
	echo $row['energy'];
echo "</td></tr><tr><td>\n"; 
	echo "<b>Attack Combat Value:</b></td><td col class='right'>\n"; 
	echo $row['acv'];
echo "</td><td col class='right'>\n"; // added </td>
	echo " (";
	echo $row['acv_sa'];
	echo " for Sailor Scout Attack)";
echo "</td>\n";
echo "</td></tr><tr><td >\n"; 
	echo "<b>Defense Combat Value:</b></td><td col class='right'>\n"; 
	echo $row['dcv'];
echo "</td><td col class='right'>\n"; // added </td>
	echo " (";
	echo $row['dcv_sa'];
	echo " for Sailor Scout Attack)";
//echo "</td>\n"; // that's an extra one
echo "</td></tr><tr><td>\n";   
	echo "<b>Total Character Points:</b></td><td col class='right'>\n"; 
	echo $row['tcp'];
echo "</td></tr>\n"; 
echo "</table>\n";

//while statement for character_attributes

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['sub']==1){ //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";
}
//end while statement

$result = mysql_query("SELECT * FROM character_attributes ORDER BY attribute_id ASC") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
echo "</td><td valign='top' width='50%' rowspan='2'>\n"; // added this whole line
echo "<table width='100%' border='0' id='stats' align='left'>\n";
echo "<tr><td colspan='7' id='th'>Character Attributes And Sub-Attributes</td></tr>\n";
echo "<tr class='sub'><td>Attribute/Sub-Attribute</td><td colspan='3' align='center'>Level</td><td colspan='3' align='center'>Points</td></tr>\n";
echo "<tr><td></td></tr>\n";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	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";
}
echo "</table></td></tr><tr><td valign='top' width='50%'>\n";		
$result = mysql_query("SELECT * FROM character_defects where identity = 'Sailor Moon' ORDER BY defect_id ASC") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
echo "<table border='0' width='100%' id='stats' align='right'>\n";
echo "<tr><td colspan='3' id='th'>Character Defects</td></tr>\n";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	echo "<tr><td>\n"; 
		echo $row['defect_id'];
		echo " ";
		echo $row['desc'];
	echo "</td><td>\n";
		echo $row['bp'];
		echo " BP";
	echo "</td></tr>\n";
}
echo "</table>\n";
echo "</td><td>\n";		
echo "</td></tr></table>\n";

Link to comment
Share on other sites

Okay, now I can see the page again with no errors, but there appears to be no changes. Also, I was thinking, since Scout Powers needs to be first on the list, I probably should assign it a a sub of 2, so we can include a statement for it as well, because right now it's lower in the list.

Link to comment
Share on other sites

Or, you could just assign a different 'sub' value to each scenario that you want. That would significantly simplify your if statement.

 

For example:

 

if sub is 1, don't indent at all, display attribute_id and desc

else if sub is 2, indent two spaces and only display attribute_id

else (if none of the above is trye), indent four spaces and only display desc

 

I'm sure the above isn't exactly what you want, but you could easily write it out that way.

Link to comment
Share on other sites

<?php
while($row = mysql_fetch_array( $result )) {
	if ($row['sub']==2){
		echo "<tr><td>\n"; 
			echo $row['attribute_id'];
			echo " ";
			echo $row['desc'];
	}
	elseif ($row['sub']==1){
		echo "<tr><td>  \n"; //indent two spaces
			echo $row['attribute_id'];
			echo " ";
			echo $row['desc'];
	}
	elseif ($row['desc']!=""){
		echo "<tr><td>   - \n"; //indent four spaces with a dash
			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";
}
?>

Link to comment
Share on other sites

Here is the whole code for the page:

 

<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="simpletree2.css" />
</head>

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("smrpg", $con);
  
//get Sailor Moon's data from the "scout" table
$result = mysql_query("SELECT * FROM scout where identity = 'Sailor Moon'") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
$birthdatemonth = $row["birthdatemonth"];
$birthdateday = $row["birthdateday"];
$birthdateyear = $row["birthdateyear"];
$birthdate = $birthdatemonth . " " . $birthdateday . ", ". $birthdateyear;
$identity = $row["identity"];

echo "<h1><center>$identity</center></h1>";
echo "<table border='0' width='100%'>";
// keeps getting the next row until there are no more to get
echo "<tr><td width='25%'>"; 
	echo "<b>Name:</b></td><td>"; 
echo $row['charactername'];
        echo "</td></tr><tr><td>"; 
	echo "<b>Element Of Influence:</b></td><td>";
echo $row['elementofinfluence'];
        echo "</td></tr><tr><td>"; 
	echo "<b>Age:</b></td><td>";
echo $row['age'];
        echo "</td></tr><tr><td>";
    echo "<b>Birthdate:</b></td><td>";
echo $birthdate;
echo "</td></tr><tr><td>";  
    echo "<b>Height:</b></td><td>"; 
echo $row['heightfeet'];
echo "&#39; ";
echo $row['heightinches'];
echo "&#34;";
        echo "</td></tr><tr><td>"; 
    echo "<b>Blood Type:</b></td><td>"; 
echo $row['bloodtype'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Hobbies:</b></td><td>"; 
echo $row['hobbies'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite Color:</b></td><td>"; 
echo $row['favoritecolor'];
        echo "</td></tr><tr><td>";   
    echo "<b>Favorite Gemstone:</b></td><td>"; 
echo $row['favoritegemstone'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite Food:</b></td><td>"; 
echo $row['favoritefood'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Least Favorite Food:</b></td><td>"; 
echo $row['leastfavoritefood'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Favorite School Subject:</b></td><td>"; 
echo $row['favoriteschoolsubject'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Least Favorite School Subject:</b></td><td>"; 
echo $row['leastfavoriteschoolsubject'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Strengths:</b></td><td>"; 
echo $row['strengths'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Weaknesses:</b></td><td>"; 
echo $row['weaknesses'];
        echo "</td></tr><tr><td>"; 
    echo "<b>Goal:</b></td><td>"; 
echo $row['goal'];
echo "...";
        echo "</td></tr></table><p>";  
echo $row['biography'];
        echo "</p>"; 
        
echo "</td></tr>"; 
echo "<tr><td> </td></tr>";

echo "</table>";

$result = mysql_query("SELECT * FROM stats where identity = 'Sailor Moon'") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
echo "<table width='100%' valign='top'><tr><td width='50%' align='right' valign='top'>\n"; // added align='right' valign='top'
echo "<table width='100%' border='0' id='stats' align='right'>\n";
// keeps getting the next row until there are no more to get
echo "<tr><td colspan='3' id='th'>Stats And Derived Values</td></tr>\n";
echo "<tr><td>\n"; 
	echo "<b>Body:</b></td><td col class='right'>\n"; 
	echo $row['body'];
echo "</td></tr><tr><td>\n"; 
	echo "<b>Mind:</b></td><td col class='right'>\n";
	echo $row['mind'];
echo "</td></tr><tr><td>\n"; 
	echo "<b>Soul:</b></td><td col class='right'>\n";
	echo $row['soul'];
echo "</td></tr><tr><td>\n";
	echo " </td></tr><tr><td>\n";
	echo "<b>Health Points:</b></td><td col class='right'>\n"; 
	echo $row['health'];
echo "</td></tr><tr><td>\n"; 
	echo "<b>Energy Points:</b></td><td col class='right'>\n"; 
	echo $row['energy'];
echo "</td></tr><tr><td>\n"; 
	echo "<b>Attack Combat Value:</b></td><td col class='right'>\n"; 
	echo $row['acv'];
echo "</td><td col class='right'>\n"; // added </td>
	echo " (";
	echo $row['acv_sa'];
	echo " for Sailor Scout Attack)";
echo "</td>\n";
echo "</td></tr><tr><td >\n"; 
	echo "<b>Defense Combat Value:</b></td><td col class='right'>\n"; 
	echo $row['dcv'];
echo "</td><td col class='right'>\n"; // added </td>
	echo " (";
	echo $row['dcv_sa'];
	echo " for Sailor Scout Attack)";
//echo "</td>\n"; // that's an extra one
echo "</td></tr><tr><td>\n";   
	echo "<b>Total Character Points:</b></td><td col class='right'>\n"; 
	echo $row['tcp'];
echo "</td></tr>\n"; 
echo "</table>\n";

//while statement for character_attributes

while($row = mysql_fetch_array( $result )) {
	if ($row['sub']==2){
		echo "<tr><td>\n"; 
			echo $row['attribute_id'];
			echo " ";
			echo $row['desc'];
	}
	elseif ($row['sub']==1){
		echo "<tr><td>  \n"; //indent two spaces
			echo $row['attribute_id'];
			echo " ";
			echo $row['desc'];
	}
	elseif ($row['desc']!=""){
		echo "<tr><td>   - \n"; //indent four spaces with a dash
			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";
}
//end while statement

$result = mysql_query("SELECT * FROM character_attributes ORDER BY attribute_id ASC") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
echo "</td><td valign='top' width='50%' rowspan='2'>\n"; // added this whole line
echo "<table width='100%' border='0' id='stats' align='left'>\n";
echo "<tr><td colspan='7' id='th'>Character Attributes And Sub-Attributes</td></tr>\n";
echo "<tr class='sub'><td>Attribute/Sub-Attribute</td><td colspan='3' align='center'>Level</td><td colspan='3' align='center'>Points</td></tr>\n";
echo "<tr><td></td></tr>\n";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	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";
}
echo "</table></td></tr><tr><td valign='top' width='50%'>\n";		
$result = mysql_query("SELECT * FROM character_defects where identity = 'Sailor Moon' ORDER BY defect_id ASC") 
or die(mysql_error());  
$row = mysql_fetch_array( $result );
echo "<table border='0' width='100%' id='stats' align='right'>\n";
echo "<tr><td colspan='3' id='th'>Character Defects</td></tr>\n";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	echo "<tr><td>\n"; 
		echo $row['defect_id'];
		echo " ";
		echo $row['desc'];
	echo "</td><td>\n";
		echo $row['bp'];
		echo " BP";
	echo "</td></tr>\n";
}
echo "</table>\n";
echo "</td><td>\n";		
echo "</td></tr></table>\n";

 

In my table within my database, here are the fields:

 

id, identity, attribute_id, sub, desc, level, and points

 

Does that help?

Link to comment
Share on other sites

Partially. I know what your fields are. From looking at your site, I sorta know what attribute_id and desc are for each row, but I have no way of knowing what your sub values are for each row. Can you copy the results of this query in tabular form here?

 

"SELECT * FROM stats where identity = 'Sailor Moon'"

Link to comment
Share on other sites

It's from:

 

SELECT * FROM character_attributes where identity = 'Sailor Moon';

 

And the results are:

 

id  identity  attribute_id  sub  desc  level  points 

      1 Sailor Moon Scout Powers 2  5 20

      2 Sailor Moon Animal Guardian 1  4 4

      3 Sailor Moon Combined Attacks 1  4 4

      4 Sailor Moon Elemental Control 1  4 12

      5 Sailor Moon Item Of Power 1 Upgraded Sailor Suit 1 2

      6 Sailor Moon Item Of Power 1 Moon Tiara 1 2

      7 Sailor Moon Item Of Power 1 Luna Pen 1 2

      8 Sailor Moon Item Of Power 1 Crescent Moon Wand 1 2

      9 Sailor Moon Item Of Power 1 Imperium Silver Crystal 5 10

      10 Sailor Moon Rejuvenation 1  5 5

      11 Sailor Moon Sailor Scout Attack 1 Moon Crystal Healing Activation 4 16

      12 Sailor Moon Sailor Scout Attack 1 Moon Scepter Elimination 4 2

      13 Sailor Moon Sailor Scout Attack 1 Cosmic Moon Power 3 1

      14 Sailor Moon Sailor Scout Attack 1 Moon Healing Activation 2 1

      15 Sailor Moon Sailor Scout Attack 1 Moon Tiara Magic 2 1

      16 Sailor Moon Acrobatics 0  1 1

      17 Sailor Moon Appearance 0  4 4

      18 Sailor Moon Art Of Distraction 0  4 3

      19 Sailor Moon Combat Mastery 0  2 4

      20 Sailor Moon Energy Bonus 0  6 6

      21 Sailor Moon Focused Combat 0 (Sailor Scout Attack) 3 3

      22 Sailor Moon Heightened Scout Power 0  7 7

      23 Sailor Moon Strong Soul 0  3 3

 

It looks a little choppy when pasting, but hopefully you can still read it okay.

Link to comment
Share on other sites

OK, it should look something like this, right?

 

Scout Powers

  Animal Guardian

  Combined Attacks

  Elemental Control

  Item Of Power Upgraded Sailor Suit

  Item Of Power Moon Tiara

  Item Of Power Luna Pen

  Item Of Power Crescent Moon Wand

  Item Of Power Imperium Silver Crystal

  Rejuvenation

  Sailor Scout Attack Moon Crystal Healing Activation

  Sailor Scout Attack Moon Scepter Elimination

  Sailor Scout Attack Cosmic Moon Power

  Sailor Scout Attack Moon Healing Activation

  Sailor Scout Attack Moon Tiara Magic

  - Acrobatics

  - Appearance

  - Art Of Distraction

  - Combat Mastery

  - Energy Bonus

  - Focused Combat 0 (Sailor Scout Attack)

  - Heightened Scout Power

  - Strong Soul

 

 

This is only the first column.

Link to comment
Share on other sites

No, like this:

 

Scout Powers

    Animal Guardian

    Combined Attacks

    Elemental Control

    Item Of Power

        - Upgraded Sailor Suit

        - Moon Tiara

        - Luna Pen

        - Crescent Moon Wand

        - Imperium Silver Crystal

    Rejuvenation

    Sailor Scout Attack

        - Moon Crystal Healing Activation

        - Moon Scepter Elimination

        - Cosmic Moon Power

        - Moon Healing Activation

        - Moon Tiara Magic

Acrobatics

Appearance

Art Of Distraction

Combat Mastery

Energy Bonus

Focused Combat (Sailor Scout Attack)

Heightened Scout Power

Strong Soul

 

Link to comment
Share on other sites

OK, that doesn't match your DB results.

 

Combining these two quotes:

if sub = 2, no indent and display before all others

if sub = 1, indent x number of spaces and also display desc

if sub = 0, no indent

and

Oh, and if desc is not blank, indent x number of spaces as well with a - at the beginning

leads me to this:

if (sub == 2) don't indent //You'll have to sort it from the DB so the 2's come first
elseif (sub==1) indent 2 spaces //I picked 2, tell me if that's not OK
elseif (desc!="") indent 3 spaces, then a dash, then another space //Again, tell me if that's not OK
else don't indent

 

That's how I understood it, but it looks like there's more to it. In you most recent example, you listed the attribute_id as a subheader in some cases. How does the code know when you want that to happen?

 

In other words, I still don't understand.

 

Try writing it out like this:

 

if (sub == 2){

<attribute_id> <desc>

}

elseif (sub==1){

<attribute_id>

  <desc>

}

elseif (desc!=""){

<attribute_id>

  - <desc>

}

else{

<attrubute_id>

}

 

Make sense?

Link to comment
Share on other sites

Well, what I did was make sub = 2 for Scout Power so that we could somehow make it come before all others,

 

then all of the attributes that are supposed to be indented have a sub = 1

then all attibutes with a desc and a sub = 1 should be indented further with a - starting off the line

 

then all attributes with a sub = 0, no indent

 

That doesn't help?

Link to comment
Share on other sites

Making sub = 2 for Scout Power won't make it come first if that's not in your SELECT statement. You should make it:

SELECT * FROM character_attributes where identity = 'Sailor Moon' ORDER BY sub DESC;

 

Also, you didn't respond to this:

 

if (sub==2){

<attribute_id> <desc>

}

elseif (sub==1){

<attribute_id>

  <desc>

}

elseif (desc!=""){

<attribute_id>

  - <desc>

}

else{

<attrubute_id>

}

 

Does that look right?

Link to comment
Share on other sites

if (sub==2){

<attribute_id> <desc>

}

elseif (sub==1){

<attribute_id>

  <desc>

}

elseif (desc!=""){

<attribute_id>

  - <desc>

}

else{

<attrubute_id>

}

 

It looks like the first part doesn't need the desc (because sub = 2 will have a blank or empty desc), and the third part I don't know if I understand right or not. Does it mean that if desc has nothing in it or something in it, to display - desc?

 

I want if desc has a blank or nothing in it, to not display it, but if it has something, to display it with a - desc.

Link to comment
Share on other sites

OK, like this?

 

if sub equals 2, display it like this (no indents):

<attribute_id> <desc>

 

else if sub equals 1, display it like this (no indent on attribute_id, on a new line three space indent on the desc):

<attribute_id>

 <desc>

 

else if desc is not blank, display it like this (no indent on attribute_id, on a new line two space indent, then dash, then a space on the desc):

<attribute_id>

  - <desc>

 

else (if the desc is blank), don't display anything

 

 

Is that right?!?

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.