Jump to content

Simplifying things...


Steve Angelis

Recommended Posts

I am building a clan website where it brings up all members from a forum database and shows it on the site.  All of this happens in one file.  When a link is clicked, say Senior Officers, it shows all commanders, lieutenants, ensigns etc, but right now I have this typed up for each rank.  It goes to the forum db, gets a speciifc rank, shows all members with that rank, repeats.  Here is what I have:

 

<?PHP
if (!isset($_GET['p'])) {
  echo '';
} else {
if ($rankset == 'adm')
{
//begin fleet admiral
$queryrk = "SELECT rank_id, rank_title, rank_image FROM phpbb_ranks where rank_id=1";
$resultrk = mysql_query($queryrk) or die("$query does not make any sence;<br>" . mysql_error());
$contentrk = mysql_fetch_array($resultrk);

$query = "SELECT user_id, username, user_rank FROM phpbb_users where user_rank='1' order by username ASC";
$result = mysql_query($query) or die("$query does not make any sence;<br>" . mysql_error());
if 
(mysql_numrows($result)>0)
{
for($n=0;$n<mysql_numrows($result);$n++) 
{
$content = mysql_fetch_array($result);
?>
<!-- Note for in here - Put ALL tables in here within the loop-->
<table width="100%" border="1" cellspacing="0">
  <tr align="left" valign="top"> 
    <td width="55%" height="254"><table width="100%" border="0" cellspacing="0">
        <tr> 
          <td align="left" valign="top"><font color="white" size="2" face="arial"> 
            <strong> 
            <legend>Player Information</legend>
            </strong></font></td>
        </tr>
        <tr> 
          <td height="21" align="left" valign="top"><table width="100%" border="1">
              <tr> 
                <td><font color="white" size="2" face="arial"><b><img 
            src="../forums/templates/subSilver/images/themes/SV/images/ranks/<?PHP echo $contentrk['rank_image']; ?>"><u><br>
                  <?PHP echo $content['username']; ?><br>
                  </u></b></font><font color="#bab9bf" size="1" face="arial">Member Info</font><font color="white" size="2" face="arial"><b><u> 
                  </u></b></font></td>
              </tr>
            </table></td>
        </tr>
        <tr> 
          <td align="left" valign="top"><table width="100%" border="1">
              <tr> 
                <td><font color="white" size="2" face="arial"><u>Character Bio:</u></font><font color="#bab9bf" size="1" face="arial"><br>
                  Bio (Separate DB)</font></td>
              </tr>
            </table></td>
        </tr>
        <tr> 
          <td align="left" valign="top"> <table width="100%" border="1">
              <tr> 
                <td><font color="white" size="2" face="arial"><u>Summary:</u></font><font color="#bab9bf" size="1" face="arial"><br>
                  Summary (Separate DB)</font></td>
              </tr>
            </table></td>
        </tr>
        <tr> 
          <td height="18" align="left" valign="top"> <table width="100%" border="1">
              <tr> 
                <td height="23"><font color="white" size="2" face="arial"><u>Service 
                  Record Summary:</u></font><br> <font color="#bab9bf" size="1" face="arial">Service Record (Separate DB)
                  </font></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
    <td width="56%"><table width="100%" border="0" cellspacing="0">
        <tr> 
          <td align="center" valign="top">Ship Image (Separate DB)</td>
        </tr>
        <tr> 
          <td align="left" valign="top"><table width="100%" border="1">
              <tr> 
                <td><font color="#bab9bf" size="1" face="arial">Ship Info (Is it needed)</font></td>
              </tr>
            </table></td>
        </tr>
        <tr> 
          <td align="left" valign="top"><table width="100%" border="1" cellspacing="0">
              <tr>
                <td><font color="white" size="2" face="arial"><strong>Commendation 
                  Medals</strong></font><br><font color="#bab9bf" size="1" face="arial">
                  Level 1</font></td>
              </tr>
            </table></td>
        </tr>
        <tr> 
          <td align="left" valign="top"><table width="100%" border="1" cellspacing="0">
              <tr> 
                <td><font color="#bab9bf" size="1" face="arial">Level 2</font></td>
              </tr>
            </table></td>
        </tr>
        <tr> 
          <td align="left" valign="top"><table width="100%" border="1" cellspacing="0">
              <tr> 
                <td><font color="#bab9bf" size="1" face="arial">Level 3</font></td>
              </tr>
            </table></td>
        </tr>
        <tr> 
          <td align="left" valign="top"><table width="100%" height="20" border="1" cellspacing="0">
              <tr>
                <td><font color="white" size="2" face="arial"><strong>Commendation 
                  & Award Ribbons</strong><br>
                  </font><font color="#bab9bf" size="1" face="arial"><center>Ribbons</center></font><font color="white" size="2" face="arial"> 
                  </font></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table><br>
<br>
<!-- End of Loop -->
<?PHP } 
}
//end fleet admiral
?>

P is a variable gotten from the link.  When Admiral is clicked adm is caught and this shows up for Fleet Admiral.  There are 5 types of Admirals so everything except for this is repeated in the typed out code:

if (!isset($_GET['p'])) {
  echo '';
} else {
if ($rankset == 'adm')
{

Is there ANY way of shortening this so that there is a loop that can do this without all that massive code being typed out for each rank?

Link to comment
https://forums.phpfreaks.com/topic/107922-simplifying-things/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.