View Single Post
Join Date: Jun 2008
Posts: 62
Reputation: PomonaGrange is an unknown quantity at this point 
Solved Threads: 3
PomonaGrange PomonaGrange is offline Offline
Junior Poster in Training

Re: show club presidents info hide everyone else's

 
0
  #7
Aug 12th, 2008
I wasn't sure how to get it to sort my my ordered list. I want the results sorted by office list. How could this be done with two seperate sql queries. NOTE: not all offices from one query are in a row.
eg.
President,
Vice President,
Other Offices...,
Secretary,
ect...

I did post this quetion in another forum and they were able to offer a simpler version of the page I wrote. (they eliminated some if statements, ect.)

I still don't have the page working so I would still appreciate help. Here is the PHP page that they suggested:
  1. <?php
  2.  
  3. session_start();
  4.  
  5. include ('./config/db.php');
  6.  
  7. $sub_name = $_GET['sub_name'];
  8.  
  9. $connection = @mysql_connect($server, $dbusername, $dbpassword)
  10. or die(mysql_error());
  11.  
  12. $db = @mysql_select_db($db_name,$connection)
  13. or die(mysql_error());
  14.  
  15. /***
  16.  * Show publicly available data
  17.  ***/
  18. // Set up the roles that should be visible to the public
  19. $rolesToShow = array("Master - President", "Overseer - Vice President", "Lecturer - Program Director", "Secretary");
  20. $roles = "'". implode("', '", $rolesToShow)."'";
  21.  
  22. // Create and execute the query
  23. $sql = "SELECT fname, lname, sub_office, email, homephone, cellphone, address, city, state, zip FROM MembersTable WHERE sub_name = '".$sub_name."' AND '".$sub_office."' IN($roles)";
  24.  
  25. $result = mysql_query($sql,$connection) or die(mysql_error());
  26.  
  27. // Display the public data
  28. while($row = mysql_fetch_row($result)) {
  29. # Show data
  30.  
  31. $fname = $row['fname'];
  32. $lname = $row['lname'];
  33. $sub_office = $row['sub_office'];
  34. $email = (isset($row['email']) ? $row['email'] : "&nbsp;");
  35. $homephone = (isset($row['homephone']) ? $row['homephone'] : "&nbsp;");
  36. $cellphone = (isset($row['cellphone']) ? $row['cellphone'] : "&nbsp;");
  37. $address = (isset($row['address']) ? $row['address'] : "&nbsp;");
  38. $city = (isset($row['city']) ? $row['city'] : "&nbsp;");
  39. $state = (isset($row['state']) ? $row['state'] : "&nbsp");
  40. $zip = (isset($row['zip']) ? $row['zip'] : "&nbsp;");
  41. }
  42.  
  43. /***
  44.  * Show member specific data
  45.  ***/
  46. // Create the SQL query based on the user's status.
  47. if($_SESSION['User']['status'] == 1) {
  48. $sql2 = "SELECT fname, lname, sub_office, email, homephone, cellphone, address, city, state, zip FROM MembersTable WHERE sub_name = '".$sub_name."' AND '".$sub_office."' NOT IN($roles)";
  49. }
  50. else {
  51. $sql2 = "SELECT fname, lname, sub_office FROM MembersTable WHERE sub_name = '".$sub_name."' AND '".$sub_office."' NOT IN($roles)";
  52. }
  53.  
  54. // Execute the query and display the results
  55. $result2 = mysql_query($sql2,$connection) or die(mysql_error());
  56.  
  57. while($row = mysql_fetch_assoc($result2)) {
  58. // Set these based on whether the data was fetched or not
  59. // The (bool ? true : false) format is basically a compact if statement.
  60. $fname = $row['fname'];
  61. $lname = $row['lname'];
  62. $sub_office = $row['sub_office'];
  63. $email = (isset($row['email']) ? $row['email'] : "&nbsp");
  64. $homephone = (isset($row['homephone']) ? $row['homephone'] : "&nbsp");
  65. $cellphone = (isset($row['cellphone']) ? $row['cellphone'] : "&nbsp");
  66. $address = (isset($row['address']) ? $row['address'] : "&nbsp");
  67. $city = (isset($row['city']) ? $row['city'] : "&nbsp");
  68. $state = (isset($row['state']) ? $row['state'] : "&nbsp");
  69. $zip = (isset($row['zip']) ? $row['zip'] : "&nbsp");
  70.  
  71. # Display data
  72.  
  73. $display_block .= "
  74. <tr>
  75. <td>$sub_office</td>
  76. <td>$fname $lname</td>
  77. <td>$homephone / $cellphone</td>
  78. <td>$email</td>
  79. <td>$address, $city, $state $zip</td>
  80. <td>$sub_name</td>
  81. </tr>";
  82. }
  83.  
  84.  
  85. $title = "<title>Officers of the ".$sub_name." Subordinate Grange</title>";
  86. ?>
  87.  
  88. <? include("./config/header.php"); ?>
  89.  
  90. </head>
  91.  
  92. <body>
  93.  
  94.  
  95.  
  96. <table width="85%" border="1" class="main"><tbody>
  97. <tr><td colspan="6"><h2>Officers of <? echo "$sub_name"; ?> Subordinate Grange</h2></td></tr>
  98.  
  99. <tr><td><b>Office</b></td> <td><b>Officer</b></td> <td><b>Home / Cell Phone #</b></td> <td><b>Email</b></td> <td><b>Address</b></td> <td><b>Subordinate Grange</b></td></tr>
  100.  
  101. <? echo "$display_block"; ?>
  102.  
  103. <tr><td colspan="6"><!-- C. FOOTER AREA -->
  104.  
  105.  
  106. <div class="footer">
  107. <? include ('./config/footerinfo.php'); ?>
  108. </div> </td></tr>
  109.  
  110. </tbody></table>
  111.  
  112.  
  113. </body>
  114. </html>
Of coarse I added a few things to try to make it work for me (eg. sql connect info ect.).
There are alot of people smarter than me, BUT at least I try to be of some help. Of coarse I'm not perfect, I need help too.
Reply With Quote