943,987 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1406
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Aug 7th, 2008
0

show club presidents info hide everyone else's

Expand Post »
HI All, I've been trying to make a membership management type script. This script would have a database with the members contact info and which office they hold, if any. The problem I am having is I would like the script to show the president's and vice president's Contact info all the time, but hide the contact info for everyone else when viewed by the general public, then if the user logs in all contact information is displayed.

Below is the part of the script that I have so far, The if logged in / out part works like I want, but I can't get it to show the President's info but hide the other members info.

php Syntax (Toggle Plain Text)
  1. if (($sub_office =="President")||($sub_office =="Vice President")||($sub_office =="Secretery")){
  2. $officer_show = "YES";}
  3. ELSE{$officer_show = "NO";}
  4.  
  5. if ($officer_show == YES){
  6. $hphone = $homephone;
  7. $cphone = $cellphone;
  8. $adress = $address;
  9. $cty = $city;
  10. $st = $state;
  11. $zp = $zip;
  12. $eml = $email;
  13. }
  14. ELSE
  15. {
  16. $hphone = " ";
  17. $cphone = " ";
  18. $adress = " ";
  19. $cty = " ";
  20. $st = " ";
  21. $zp = " ";
  22. $eml = " ";
  23. }
  24. if($_SESSION['auth']['status'] == 1){
  25. // do stuff here
  26. $display_block .= "
  27. <tr>
  28. <td>$sub_office</td>
  29. <td>$fname $lname</td>
  30. <td>$hphone / $cphone</td>
  31. <td>$eml</td>
  32. <td>$adress, $cty, $st $zp</td>
  33. <td>$sub_name</td>
  34. </tr>";
  35. }
  36.  
  37. ELSE {
  38. $display_block .= "
  39. <tr>
  40. <td>$sub_office</td>
  41. <td>$fname $lname</td>
  42. <td>$hphone / $cphone</td>
  43. <td>$eml</td>
  44. <td>$adress, $cty, $st $zp</td>
  45. <td>$sub_name</td>
  46. </tr>";
  47. }
  48. }

I Have also seen the if ($sub_office =="President") done like this if ($sub_office !="President")
I can't seem to get it to work either way. If there is a better way of doing any of this, let me know. I would appreciate any help.
Last edited by peter_budo; Aug 7th, 2008 at 4:16 pm. Reason: Keep It Organized - please use [code] tags
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008
Aug 7th, 2008
0

Re: show club presidents info hide everyone else's

Well, I don't know all your database, but here's a sample script I would use:

php Syntax (Toggle Plain Text)
  1. if (!logged_in)
  2. {
  3. $query1 = mysql_query("SELECT * FROM membersinfo WHERE id = 'president'");
  4. while ($row = mysql_fetch array($sql))
  5. {
  6. echo "<tr>
  7. <td>$sub_office</td>
  8. <td>$fname $lname</td>
  9. <td>$hphone / $cphone</td>
  10. <td>$eml</td>
  11. <td>$adress, $cty, $st $zp</td>
  12. <td>$sub_name</td>
  13. </tr>";
  14. }
  15. } elseif (logged_in)
  16. {
  17. $query2 = mysql_query("SELECT * FROM membersinfo");
  18. while ($row = mysql_fetch array($sql))
  19. {
  20. echo "<tr>
  21. <td>$sub_office</td>
  22. <td>$fname $lname</td>
  23. <td>$hphone / $cphone</td>
  24. <td>$eml</td>
  25. <td>$adress, $cty, $st $zp</td>
  26. <td>$sub_name</td>
  27. </tr>";
  28. }
  29. }
Last edited by Demiloy; Aug 7th, 2008 at 11:00 am.
Reputation Points: 12
Solved Threads: 6
Light Poster
Demiloy is offline Offline
48 posts
since Aug 2008
Aug 7th, 2008
0

Re: show club presidents info hide everyone else's

This would work ok, but I forgot to mention that I still want to show everyone's name. I only want to show the contact info for the president, VP, and Secretary. Only the name and 'office' would be shown for the other members.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008
Aug 7th, 2008
0

Re: show club presidents info hide everyone else's

In which case, you could change the query. Under the if(!logged_in) part, after the first query:

php Syntax (Toggle Plain Text)
  1. $names = mysql_query("SELECT name FROM members WHERE id != 'president'");
  2.  
  3. while ($info = mysql_fetch array($names))
  4. {
  5. // echo names
  6. }
  7. //continue on with elseif

That should do the trick.
Last edited by Demiloy; Aug 7th, 2008 at 11:16 pm.
Reputation Points: 12
Solved Threads: 6
Light Poster
Demiloy is offline Offline
48 posts
since Aug 2008
Aug 8th, 2008
0

Re: show club presidents info hide everyone else's

I would prefer not to change the sql query. This would create a plroblem in the list and also would make it difficult to do the logged in view. I'm not sure why the if() statements aren't working. I think they should. Thanks for the help anyway.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008
Aug 8th, 2008
0

Re: show club presidents info hide everyone else's

What problem exactly would you have by adding the sql query?
Reputation Points: 12
Solved Threads: 6
Light Poster
Demiloy is offline Offline
48 posts
since Aug 2008
Aug 12th, 2008
0

Re: show club presidents info hide everyone else's

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:
PHP Syntax (Toggle Plain Text)
  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.).
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008
Aug 12th, 2008
0

Re: show club presidents info hide everyone else's

I only found one type of thing wrong on this page, all of your
$zip = (isset($row['zip']) ? $row['zip'] : "&nbsp;");
lines have an unmatched bracket ) on the end of them.
So I changed them to this
PHP Syntax (Toggle Plain Text)
  1. $zip = ( isset($row['zip'] ) ? $row['zip'] : "&nbsp";
And played around with the rest of the code some too ... but no promises
PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. session_start();
  4.  
  5. include( './config/db.php' );
  6.  
  7. $sub_name = $_GET['sub_name'];
  8.  
  9. $link = @mysql_connect( $server, $dbusername, $dbpassword ) or die(mysql_error());
  10.  
  11. $db = @mysql_select_db( $db_name ) or die(mysql_error());
  12.  
  13. /***
  14.  * Show publicly available data
  15.  ***/
  16. // Set up the roles that should be visible to the public
  17. $rolesToShow = array( "Master - President", "Overseer - Vice President", "Lecturer - Program Director", "Secretary" );
  18. $roles = "'".implode( "', '", $rolesToShow )."'";
  19.  
  20. // Create and execute the query
  21. $sql = "SELECT * FROM `MembersTable` WHERE sub_name='$sub_name' AND '$sub_office' IN($roles)";
  22.  
  23. $result = mysql_query( $sql ) or die( mysql_error() );
  24.  
  25. // Display the public data
  26. while( $row = mysql_fetch_row( $result ) ) {
  27. # Show data
  28. $fname = $row['fname'];
  29. $lname = $row['lname'];
  30. $sub_office = $row['sub_office'];
  31. $email = ( isset($row['email'] ) ? $row['email'] : "&nbsp;";
  32. $homephone = ( isset($row['homephone'] ) ? $row['homephone'] : "&nbsp;";
  33. $cellphone = ( isset($row['cellphone'] ) ? $row['cellphone'] : "&nbsp;";
  34. $address = ( isset($row['address'] ) ? $row['address'] : "&nbsp;";
  35. $city = ( isset($row['city'] ) ? $row['city'] : "&nbsp;";
  36. $state = ( isset($row['state'] ) ? $row['state'] : "&nbsp";
  37. $zip = ( isset($row['zip'] ) ? $row['zip'] : "&nbsp;";
  38. }
  39.  
  40. /***
  41.  * Show member specific data
  42.  ***/
  43. // Create the SQL query based on the user's status.
  44. if( $_SESSION['User']['status'] == 1 ) {
  45. $sql2 = "SELECT * FROM MembersTable WHERE sub_name = '$sub_name' AND '$sub_office' NOT IN($roles)";
  46. } else {
  47. $sql2 = "SELECT fname, lname, sub_office FROM MembersTable WHERE sub_name = '$sub_name' AND '$sub_office' NOT IN($roles)";
  48. }
  49.  
  50. // Execute the query and display the results
  51. $result2 = mysql_query( $sql2 ) or die( mysql_error() );
  52.  
  53. while ( $row = mysql_fetch_assoc( $result2 ) ) {
  54. // Set these based on whether the data was fetched or not
  55. // The (bool ? true : false) format is basically a compact if statement.
  56. $fname = $row['fname'];
  57. $lname = $row['lname'];
  58. $sub_office = $row['sub_office'];
  59. $email = ( isset($row['email'] ) ? $row['email'] : "&nbsp";
  60. $homephone = ( isset($row['homephone'] ) ? $row['homephone'] : "&nbsp";
  61. $cellphone = ( isset($row['cellphone'] ) ? $row['cellphone'] : "&nbsp";
  62. $address = ( isset($row['address'] ) ? $row['address'] : "&nbsp";
  63. $city = ( isset($row['city'] ) ? $row['city'] : "&nbsp";
  64. $state = ( isset($row['state'] ) ? $row['state'] : "&nbsp";
  65. $zip = ( isset($row['zip'] ) ? $row['zip'] : "&nbsp";
  66.  
  67. # Display data
  68. $display_block .= <<<ENDLINE
  69. <tr>
  70. <td>$sub_office</td>
  71. <td>$fname $lname</td>
  72. <td>$homephone / $cellphone</td>
  73. <td>$email</td>
  74. <td>$address, $city, $state $zip</td>
  75. <td>$sub_name</td>
  76. </tr>
  77. ENDLINE;
  78. }
  79.  
  80. $title = "<title>Officers of the $sub_name Subordinate Grange</title>";
  81. ?>
  82. <? include("./config/header.php"); ?>
  83. </head>
  84. <body>
  85. <table width="85%" border="1" class="main">
  86. <tbody>
  87. <tr>
  88. <td colspan="6"><h2>Officers of <? echo "$sub_name"; ?> Subordinate Grange</h2></td>
  89. </tr>
  90. <tr>
  91. <td><b>Office</b></td>
  92. <td><b>Officer</b></td>
  93. <td><b>Home / Cell Phone #</b></td>
  94. <td><b>Email</b></td>
  95. <td><b>Address</b></td>
  96. <td><b>Subordinate Grange</b></td>
  97. </tr>
  98. <? echo "$display_block"; ?>
  99. <tr>
  100. <td colspan="6"><!-- C. FOOTER AREA -->
  101. <div class="footer">
  102. <? include ('./config/footerinfo.php'); ?>
  103. </div></td>
  104. </tr>
  105. </tbody>
  106. </table>
  107. </body>
  108. </html>
Last edited by langsor; Aug 12th, 2008 at 7:22 pm.
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 posts
since Aug 2008
Aug 12th, 2008
0

Re: show club presidents info hide everyone else's

This is still a no go. also if you look at
$zip = (isset($row['zip']) ? $row['zip'] : "&nbsp;");
They are not mis matched.
Oh well, I'll keep fooling with it until I get it figured out.
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
PomonaGrange is offline Offline
67 posts
since Jun 2008
Aug 12th, 2008
0

Re: show club presidents info hide everyone else's

You're right about the not-mismatched ... guess I had already fooled with it some before noticing that I had un-matched the brackets :-\

So, what's not working...are you getting errors, is the html not formatting correctly, are you not getting data from the database ... ?

Just trying to help.
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC