show club presidents info hide everyone else's

Thread Solved

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
  #11
Aug 12th, 2008
The names and offices show up properly, but none of the contact info shows up, wether logged in or not. I would assume that the sql query's are working fine, just the if logged in and if officer aren't working.

I do appreciate the help!
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 Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: show club presidents info hide everyone else's

 
0
  #12
Aug 13th, 2008
Okay, I came in after-the-fact on this post and now I'm going to back up and take it from the start ... wish me luck.

First of all you need to test and make certain you have a 'true' value for session status when a member is logged in. That could be your only problem right now.

Please check my code to make sure all of your database login and table field names are correct -- change my code values if they are not
And check that the SESSION names-values are correct, and working
  1. <?php
  2.  
  3. include( './config/db.php' );
  4. $sub_name = $_GET['sub_name']; // If it's a form value, you probably want to use $_POST['sub_name'] with <form method="POST">
  5.  
  6. $officers = array( "President", "Vice President", "Secretery" ); // edit to suite your needs ...
  7.  
  8. session_start();
  9. $session = ( $_SESSION['auth']['status'] == 1 ) ? TRUE : FALSE; // or ? ... ( $_SESSION['User']['status'] == 1 )
  10.  
  11. $link = @mysql_connect( $host, $user, $pass ) or die( mysql_error() );
  12. @mysql_select_db( $dbase ) or die( mysql_error() );
  13. // make sure these are the names of the fields in your database, change them in
  14. // the $sql query `email` (etc) and the $obj->email values (bellow) if they are not ...
  15. $sql = "SELECT `fname`, `lname`, `sub_office`, `email`, `homephone`, `cellphone`, `address`, `city`, `state`, `zip` FROM `MembersTable` WHERE sub_name='$sub_name'";
  16. // You can just use this, if thesse are all or most of the values in the table ...
  17. // $sql = "SELECT * FROM `MembersTable` WHERE sub_name='$sub_name'";
  18. $result = mysql_query( $sql ) or die( mysql_error() );
  19.  
  20. $html = '';
  21. while ( $obj = mysql_fetch_object( $result ) ) {
  22. $html .= <<<ENDHTML
  23. <tr>
  24. <td>$obj->sub_office</td>
  25. <td>$obj->fname $obj->lname</td>
  26. ENDHTML;
  27. if ( $session || in_array( $obj->sub_office, $officers ) ) {
  28. $html .=<<<ENDHTML
  29. <td>$$obj->hphone / $cphone</td>
  30. <td>$$obj->email</td>
  31. <td>$$obj->address, $$obj->cty, $$obj->state $$obj->zip</td>
  32. <td>$$obj->sub_name</td>
  33. ENDHTML;
  34. }
  35. $html .= " <\tr>\n";
  36. }
  37.  
  38. $title = "<title>Officers of the $sub_name Subordinate Grange</title>";
  39.  
  40. ?>
  41. <?php include("./config/header.php"); ?>
  42. </head>
  43. <body>
  44. <table width="85%" border="1" class="main">
  45. <tbody>
  46. <tr>
  47. <td colspan="6"><h2>Officers of <? echo "$sub_name"; ?> Subordinate Grange</h2></td>
  48. </tr>
  49. <tr>
  50. <td><b>Office</b></td>
  51. <td><b>Officer</b></td>
  52. <td><b>Home / Cell Phone #</b></td>
  53. <td><b>Email</b></td>
  54. <td><b>Address</b></td>
  55. <td><b>Subordinate Grange</b></td>
  56. </tr>
  57. <?php print $html; ?>
  58. <tr>
  59. <td colspan="6"><!-- C. FOOTER AREA -->
  60. <div class="footer">
  61. <?php include ('./config/footerinfo.php'); ?>
  62. </div></td>
  63. </tr>
  64. </tbody>
  65. </table>
  66. </body>
  67. </html>

Okay, my eyes are so blurry I can't read...hope I didn't make too many type-os

Ciao
Reply With Quote Quick reply to this message  
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
  #13
Aug 13th, 2008
Hi, yours seems to be really close except:
There is a bunch of < r> before the table (I can't find where they are coming from),
I also would like to insert &nbsp; into a cell if the sql row is empty for that column (to make the table look better)

I did have to make a couple of changes to make things work, but this is the closest I've gotten yet.

  1. <?php
  2.  
  3. include( './config/db.php' );
  4.  
  5. $sub_name = $_GET['sub_name']; // If it's a form value, you probably want to use $_POST['sub_name'] with <form method="POST">
  6.  
  7. $officers = array( "Master - President", "Overseer - Vice President", "Secretery", "Lecturer - Program Director" ); // edit to suite your needs ...
  8.  
  9. session_start();
  10. $session = ( $_SESSION['auth']['status'] == 1 ) ? TRUE : FALSE; // or ? ... ( $_SESSION['User']['status'] == 1 )
  11.  
  12. $link = @mysql_connect( $server, $dbusername, $dbpassword ) or die( mysql_error() );
  13. @mysql_select_db( $db_name ) or die( mysql_error() );
  14. // make sure these are the names of the fields in your database, change them in
  15. // the $sql query `email` (etc) and the $obj->email values (bellow) if they are not ...
  16.  
  17. $sql = "SELECT `fname`, `lname`, `sub_office`, `email`, `homephone`, `cellphone`, `address`, `city`, `state`, `zip`,
  18. (SELECT
  19. CASE
  20. WHEN `sub_office` = 'Master - President' THEN 1
  21. WHEN `sub_office` = 'Overseer - Vice President' THEN 2
  22. WHEN `sub_office` = 'Lecturer - Program Director' THEN 3
  23. WHEN `sub_office` = 'Steward' THEN 4
  24. WHEN `sub_office` = 'Assistant Steward' THEN 5
  25. WHEN `sub_office` = 'Lady Assistant Steward' THEN 6
  26. WHEN `sub_office` = 'Chaplain' THEN 7
  27. WHEN `sub_office` = 'Treasurer' THEN 8
  28. WHEN `sub_office` = 'Building Treasurer' THEN 9
  29. WHEN `sub_office` = 'Secretary' THEN 10
  30. WHEN `sub_office` = 'Gate Keeper' THEN 11
  31. WHEN `sub_office` = 'Flora' THEN 12
  32. WHEN `sub_office` = 'Pomona' THEN 13
  33. WHEN `sub_office` = 'Ceres' THEN 14
  34. WHEN `sub_office` = 'Executive Committee' THEN 15
  35. WHEN `sub_office` = 'Pianist' THEN 16
  36. WHEN `sub_office` = 'Leadership' THEN 17
  37. WHEN `sub_office` = 'Membership' THEN 18
  38. WHEN `sub_office` = 'Legislative' THEN 19
  39. WHEN `sub_office` = 'Family Activities' THEN 20
  40. WHEN `sub_office` = 'Community Service' THEN 21
  41. WHEN `sub_office` = 'Fun Committee' THEN 22
  42. ELSE 23
  43. END) as sort
  44. FROM `MembersTable` WHERE sub_name='$sub_name'
  45.  
  46. ORDER BY sort ASC";
  47.  
  48. // You can just use this, if thesse are all or most of the values in the table ...
  49. // $sql = "SELECT * FROM `MembersTable` WHERE sub_name='$sub_name'";
  50. $result = mysql_query( $sql ) or die( mysql_error() );
  51.  
  52. $html = '';
  53. while ( $obj = mysql_fetch_object( $result ) ) {
  54. $html .= <<<ENDHTML
  55. <tr>
  56. <td>$obj->sub_office</td>
  57. <td>$obj->fname $obj->lname</td>
  58. ENDHTML;
  59. if ( $session || in_array( $obj->sub_office, $officers ) ) {
  60. $html .=<<<ENDHTML
  61. <td>$obj->homephone / $obj->cellphone</td>
  62. <td>$obj->email</td>
  63. <td>$obj->address, $obj->city, $obj->state $obj->zip</td>
  64. <td>$obj->sub_name</td>
  65. ENDHTML;
  66. }
  67. $html .= " <\tr>\n";
  68. }
  69.  
  70. $title = "<title>Officers of the $sub_name Subordinate Grange</title>";
  71.  
  72. ?>
  73. <?php include("./config/header.php"); ?>
  74. </head>
  75. <body>
  76. <table width="85%" border="1" class="main">
  77. <tbody>
  78. <tr>
  79. <td colspan="6"><h2>Officers of <? echo "$sub_name"; ?> Subordinate Grange</h2></td>
  80. </tr>
  81. <tr>
  82. <td><b>Office</b></td>
  83. <td><b>Officer</b></td>
  84. <td><b>Home / Cell Phone #</b></td>
  85. <td><b>Email</b></td>
  86. <td><b>Address</b></td>
  87. <td><b>Subordinate Grange</b></td>
  88. </tr>
  89. <?php print $html; ?>
  90. <tr>
  91. <td colspan="6"><!-- C. FOOTER AREA -->
  92. <div class="footer">
  93. <?php include ('./config/footerinfo.php'); ?>
  94. </div></td>
  95. </tr>
  96. </tbody>
  97. </table>
  98. </body>
  99. </html>

I added the SELECT CASE so I could order the offices in a set order.
I do have the 'sub_name' sent from a form currently, but I don't want to switch it to the POST method. I want to keep it so I can make a link and have it go directly to a certain one, therefore I believe it should stay as GET.

Thanks for all your help so far.
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 Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: show club presidents info hide everyone else's

 
0
  #14
Aug 13th, 2008
I was laying there in bed trying to go to sleep and realized I had not added the contingency for empty values or empty table cells ...

Try this
  1. $html = '';
  2. while ( $obj = mysql_fetch_object( $result ) ) {
  3. $display = ( $session || in_array( $obj->sub_office, $officers ) ? TRUE : FALSE;
  4. $homephone = ( $display && $obj->homephone ) ? $obj->homephone : '&nbsp';
  5. $cellphone = ( $display && $obj->cellphone ) ? $obj->cellphone : '&nbsp';
  6. $email = ( $display && $obj->email ) ? $obj->email : '&nbsp';
  7. $address = ( $display && $obj->address ) ? $obj->address : '&nbsp';
  8. $city = ( $display && $obj->city ) ? $obj->city : '&nbsp';
  9. $state = ( $display && $obj->state ) ? $obj->state : '&nbsp';
  10. $zip = ( $display && $obj->zip ) ? $obj->zip : '&nbsp';
  11. $sub_name = ( $display && $obj->sub_name ) ? $obj->sub_name : '&nbsp';
  12. $html .= <<<ENDHTML
  13. <tr>
  14. <td>$obj->sub_office</td>
  15. <td>$obj->fname $obj->lname</td>
  16. <td>$homephone / $cellphone</td>
  17. <td>$email</td>
  18. <td>$address, $city, $state $zip</td>
  19. <td>$sub_name</td>
  20. <\tr>
  21. ENDHTML;
  22. }
Hope this works for you.

Out of curiosity, what are you doing with these lines in the SELECT statement?
  1. (SELECT
  2. CASE
  3. WHEN `sub_office` = 'Master - President' THEN 1

...
Reply With Quote Quick reply to this message  
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
  #15
Aug 13th, 2008
Ok, First off the table looks better, but for some reason I'm getting < r> tags at the end of each row. These are place before the table. I don't understand where they are coming from.

The

  1. (SELECT
  2. CASE
  3. WHEN `sub_office` = 'Master - President' THEN 1

lines are to sort the results by a list I set. I don't want the rows sorted alphabetically. I want them according to office, eg the most important office (president) office to the lesser important (the committees).

Thanks Again for you wonderful help.
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 Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: show club presidents info hide everyone else's

 
0
  #16
Aug 13th, 2008
Originally Posted by PomonaGrange View Post
I'm getting < r> tags at the end of each row. These are place before the table. I don't understand where they are coming from
I don't see them from the code you submitted earlier or my updates ... if you want to post your code in total again I'll sift through that for them.

Could they be coming from one of the include files?

Could they be coming from some copy-paste-replacement you made and left a telltale < r> (say from <tr> or <br>)?

Just guessing

And you're welcome about the help :-)
Reply With Quote Quick reply to this message  
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
  #17
Aug 13th, 2008
Hi again. I just found where they were coming from. you had typed <\tr> when it should have been </tr>. Once I changed that it made everything show, if I dare say, perfectly. By the way I knew the include files were fine.

Thanks Alot!
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 Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: show club presidents info hide everyone else's

 
0
  #18
Aug 13th, 2008
I knew I was pretty tired when I wrote that stuff...glad you found the source of the problem.

Take care
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC