control functions executing in the wrong order

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Tehquickness
Forum Commoner
Posts: 32
Joined: Mon Oct 24, 2005 11:31 pm

control functions executing in the wrong order

Post by Tehquickness »

So here is what I have, the switch control is obviously before the while control:

Code: Select all

foreach ($offices as $status){
  switch($status):
   case 'President':
      print "<h1> Officers </h1>";
      break;
   case 'Active':
      print "<h1>Active Members</h1>";
      break;
   case 'Pledge':
     print "<h1>Pledges</h1>";
     break;
   default:
    endswitch;
  $query = "SELECT * from mgmemberpage WHERE status = '$status' ORDER BY last_name ASC";
  $result = mysql_query($query, $conn);
  while ($memberinfoarray = mysql_fetch_array($result)){
?>
  <tr>
     <td>
        <p class="membername"><?php print $memberinfoarray['first_name']." ".$memberinfoarray['last_name']; ?><br />
        <p class="members"><?php print $memberinfoarray['status']?><br />
        <?php print $memberinfoarray['year']; ?><br />
        <?php print $memberinfoarray['major']; ?><br />
        <a href="http://www.millergirls.org/email.php?email=<?php print $memberinfoarray['id']; ?>">Email <?php print $memberpagearray['first_name']?></a><br /></p></p>
    </td>
  </tr>
</table>

<?php
}

  
  }

and here is what prints out:

Amanda Roberson
President
Senior
Public Relations
Email

Officers

The heading for the lists (created by the switch) is always under the list it self (created by the while)
I am totally stumped.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

It looks like you have the <h1>'s wedged in before after the <table> tag (if there even is one). The browser might put the text anywhere if the HTML is misformed.
(#10850)
pennythetuff
Forum Newbie
Posts: 22
Joined: Sun Feb 19, 2006 6:05 pm
Location: Kokomo, Indiana

Post by pennythetuff »

arborint is right. The headings are in the table, but they're not bound by any type of structure (<tr> <td>).

Code: Select all

foreach ($offices as $status){
  switch($status):
   case 'President':
      print "<tr><td><h1> Officers </h1></td></tr>";
      break;
   case 'Active':
      print "<tr><td><h1>Active Members</h1></td></tr>";
      break;
   case 'Pledge':
     print "<tr><td><h1>Pledges</h1></td></tr>";
     break;
   default:
    endswitch;
  $query = "SELECT * from mgmemberpage WHERE status = '$status' ORDER BY last_name ASC";
  $result = mysql_query($query, $conn);
  while ($memberinfoarray = mysql_fetch_array($result)){
?>
  <tr>
     <td>
        <p class="membername"><?php print $memberinfoarray['first_name']." ".$memberinfoarray['last_name']; ?><br />
        <p class="members"><?php print $memberinfoarray['status']?><br />
        <?php print $memberinfoarray['year']; ?><br />
        <?php print $memberinfoarray['major']; ?><br />
        <a href="http://www.millergirls.org/email.php?email=<?php print $memberinfoarray['id']; ?>">Email <?php print $memberpagearray['first_name']?></a><br /></p></p>
    </td>
  </tr>
</table>
[php]
<?php
} [/php]
Post Reply