Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules
Author Message
Donovan
Client



Joined: Oct 07, 2003
Posts: 735
Location: Ohio

PostPosted: Tue Nov 09, 2004 11:19 pm Reply with quote

What I am trying to do is to break my roster up by unit and display the header for each unit.

Headquarters
1st Platoon
2nd Platoon
..etc

each has it's own unit_id

unit_id = 1
unit_id = 2
..etc

http://www.3rd-infantry-division.net/modules.php?name=roster

So for each unit they would have it's own header info
Name, Position, Weapon, Status

Here is the code:

Code:
//begin layout of table to include loop for different units 

//lists the header for the table displaying what's what

for ( $counter = 1; $counter <= 5; $counter += 1) {
    $sql = "SELECT unit_id, unit_name, unit_nick FROM roster_units";
    $result = $db->sql_query($sql);
    while ( $row = $db->sql_fetchrow($result) ) {
            $unit_id = $row['unit_id'];
            $unit_name = $row['unit_name'];     
            $unit__nick = $row["unit_nick"];
     
    echo "<table border=0 width='100%' cellpadding='5'><tr>";
    echo "<table border=0 width='100%' cellpadding='3'><tr><th width='100%'>$unit_name $unit_nick</th>";
    echo "<table border=0 width='100%' cellpadding='3'><tr><th width='10%'>Rank</th><th width='15%'><b>Name</b></th><th width='20%'>Weapon</th><th width='25%'>Position</th><th width='15%'>ICQ</th><th width='20%'>Status</th>";
    echo "</tr>";
    }

    $sql = "SELECT a.u_handle, a.u_rank, a.uniqueid, a.unit, a.weapon, a.position, a.icq, a.status, b.rank_image, b.rankname FROM roster_members a, roster_ranks b WHERE a.unit_id = $counter ORDER BY b.rank_id";
    $result = $db->sql_query($sql);
    while ( $row = $db->sql_fetchrow($result) ) {
            $rankname = $row['rankname'];
            $ri = $row['rank_image'];     
            $hname = $row["u_handle"];
            $uid = $row["uniqueid"];
            $weapon = $row["weapon"];
            $position = $row["position"];
            $icq = $row["icq"];
            $status = $row["status"];             
            if ($row["rank_image"] =="") {
            $ri = " "; 
            } else {
            $ri = "<img src='modules/roster/images/ranks/$row[rank_image]'>"; 

        }
     
    //fill the table with values from roster
    echo "<td width='10%' class='row1' align='center'>$ri</td><td class='row1' width='25%'><a class=\"mainroster\" href=\"modules.php?name=$module_name&file=rosterprofile&handlename=$uid\">$hname</a><td width='20%' class='row1' align='center'>$weapon</td><td width='25%' class='row1' align='center'>$position</td><td width='15%' class='row1' align='center'>$icq</td><td width='20%' class='row1' align='center'>$status</td>";
    echo "</tr>";           
  }


One guy told me to do the following:

Quote:
Use a single query with a JOIN that extracts the unit data with the person data; order by unit and then, I suppose, rank.

Display the unit data for the first person, and store the unit id in a var. Then display the person data for the first person. Compare the unit id for each subsequent person until the unit changes. When it does, display the data for the new unit and so on.

The main changes to your existing code are the single sql query and the code for displaying the unit data will now be within your while loop, controlled by an if clause.


But I am not following him very well, cause I learn better by example. Neutral I have tried to get this working but need some guidance.
 
View user's profile Send private message Visit poster's website ICQ Number
Donovan







PostPosted: Thu Nov 11, 2004 1:52 pm Reply with quote

It looks like I don't have a table closed.

http://www.3rd-infantry-division.net/modules.php?name=MILPACS&file=roster

It won't let me post my code. Mad

Edit// I'll try and edit the one above.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Modules

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©