PHP Looping

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   PHP Looping
Donovan
CZ Active Member
 Codezwiz Site Donator
usa.gif ohio.gif
Occupation: Web Developer
Gender: Male
Fav. Sports Team: St Louis Cardinals
Status: Offline
Joined: Dec 03, 2003
0.02 posts per day
Posts: 160
Points: 9,216
   
I have a table called roster_award that has the following fields
award_id
award_name
award_image
award_description

Would this loop gather all the nessecary info if I wanted to loop thru this and place in a table all the awards any of my members have. One line for each award and it's description.

$result3 = $db->sql_query("SELECT 'award_name', 'award_description' FROM roster_awards a JOIN roster_profile b WHERE a.award_id = b.award_id");
   while ( $row = $db->sql_fetchrow($result3) ) {
      $awardname = $row["award_name"];
      $awarddetail = $row["award_decription"];
        if (!$result3) {
          echo("<p>Error performing query: " . mysql_error() . "</p>");
          exit();
        }
   }


Thanks


Back to top Reply with quote
#2   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,475
   
Correct but you need your show html inside of the loop.




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#3   re: PHP Looping
Donovan
CZ Active Member
 Codezwiz Site Donator
usa.gif ohio.gif
Occupation: Web Developer
Gender: Male
Fav. Sports Team: St Louis Cardinals
Status: Offline
Joined: Dec 03, 2003
0.02 posts per day
Posts: 160
Points: 9,216
   
My latest is trying to get my roster to break on unit so it would list Headquarters and then the column heading then 1st Platoon and column headings, etc...

Any help is appreciated.


//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>";          
  }
   
    echo "</table><br /><hr noShade>";
}   
    //end of the rank loop

CloseTable();
include("footer.php");
?>



Back to top Reply with quote
#4   re: PHP Looping
Donovan
CZ Active Member
 Codezwiz Site Donator
usa.gif ohio.gif
Occupation: Web Developer
Gender: Male
Fav. Sports Team: St Louis Cardinals
Status: Offline
Joined: Dec 03, 2003
0.02 posts per day
Posts: 160
Points: 9,216
   
Bump.

Any ideas out there on how I could get this to work.

If I break my roster up by unit, I think it would look a whole lot better.
[ Register or login to view links on this board. ]


Is my logic right setting up the for loop?



Back to top Reply with quote
#5   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,475
   
Your stopping the top loop after the $unit_name $unit_nick so that onle gets shown once? Or is it supposed to be the top of each section?

Whats the


for ( $counter = 1; $counter <= 5; $counter += 1) {


for?



_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
#6   
Donovan
CZ Active Member
 Codezwiz Site Donator
usa.gif ohio.gif
Occupation: Web Developer
Gender: Male
Fav. Sports Team: St Louis Cardinals
Status: Offline
Joined: Dec 03, 2003
0.02 posts per day
Posts: 160
Points: 9,216
   


Originally posted by Telli @ Fri Nov 05, 2004 4:27 pm:

Your stopping the top loop after the $unit_name $unit_nick so that onle gets shown once? Or is it supposed to be the top of each section?

Whats the


for ( $counter = 1; $counter <= 5; $counter += 1) {


for?


I want the unit_name and unit_nick to display for each unit, then display all the members for that unit with the header info at the top. Name, Position, Weapon, Status.

The for loop was because I only have 5 units all with thier own unit_id and though I could get it to work that way.

Headquarters
1st Platoon
2nd Platoon
3rd Platoon
Reserves


Back to top Reply with quote
#7   
aUsTiN
CZ Active Member
usa.gif georgia.gif
Age: 41
Gender: Male
Website:
Status: Offline
Joined: Sep 09, 2003
0.02 posts per day
Posts: 142
Points: 57
  MSN Messenger 
The for is another type of array. It will stop the code after 5 times through the loop.



Back to top Reply with quote
#8   
Telli
Site Admin
Occupation: Self Employed
Age: 46
Gender: Male
Fav. Sports Team: Detroit Red Wings
Website:
Status: Offline
Joined: May 26, 2003
1.03 posts per day
Posts: 8089
Points: 494,475
   


Originally posted by aUsTiN @ Fri Nov 12, 2004 6:38 am:

The for is another type of array. It will stop the code after 5 times through the loop.


Really? icon_rolleyes.gif


LOL I was asking what he was using it for as he doesn't need it.




_________________
The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee. Ezekiel 25:17
Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
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 cannot attach files in this forum
You cannot download files in this forum