473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

show club presidents info hide everyone else's

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, for everyone.

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]if (($sub_office =="President")||($sub_office =="Vice President")||($sub_office =="Secretery")){ $officer_show = "YES";} ELSE{$officer_show = "NO";} if ($officer_show == YES){$hphone = $homephone;$cphone = $cellphone;$adress = $address;$cty = $city;$st = $state;$zp = $zip;$eml = $email;}ELSE{$hphone = "&nbsp;";$cphone = "&nbsp;";$adress = "&nbsp;";$cty = "&nbsp;";$st = "&nbsp;";$zp = "&nbsp;";$eml = "&nbsp;";} if($_SESSION['auth']['status'] == 1){ // do stuff here$display_block .= "<tr> <td>$sub_office</td> <td>$fname $lname</td> <td>$hphone / $cphone</td> <td>$eml</td> <td>$adress, $cty, $st $zp</td> <td>$sub_name</td></tr>"; } ELSE {$display_block .= "<tr> <td>$sub_office</td> <td>$fname $lname</td> <td>$hphone / $cphone</td> <td>$eml</td> <td>$adress, $cty, $st $zp</td> <td>$sub_name</td></tr>"; }} if (($sub_office =="President")||($sub_office =="Vice President")||($sub_office =="Secretery")){
$officer_show = "YES";}
ELSE{$officer_show = "NO";}

if ($officer_show == YES){
$hphone = $homephone;
$cphone = $cellphone;
$adress = $address;
$cty = $city;
$st = $state;
$zp = $zip;
$eml = $email;
}
ELSE
{
$hphone = "&nbsp;";
$cphone = "&nbsp;";
$adress = "&nbsp;";
$cty = "&nbsp;";
$st = "&nbsp;";
$zp = "&nbsp;";
$eml = "&nbsp;";
}
if($_SESSION['auth']['status'] == 1){
// do stuff here
$display_block .= "
<tr>
<td>$sub_office</td>
<td>$fname $lname</td>
<td>$hphone / $cphone</td>
<td>$eml</td>
<td>$adress, $cty, $st $zp</td>
<td>$sub_name</td>
</tr>";
}

ELSE {
$display_block .= "
<tr>
<td>$sub_office</td>
<td>$fname $lname</td>
<td>$hphone / $cphone</td>
<td>$eml</td>
<td>$adress, $cty, $st $zp</td>
<td>$sub_name</td>
</tr>";
}
} [/PHP]

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.
Another thing I should mention is that I want to show the contact info for the club president and a couple other offices, but hide the contact info for everyone else. I still want to show everyone's name, just hide their contact info. I posted this question in another forum and the suggestion I got from their is to change the sql query. I don't want to do that though.

If there is a better way of doing any of this, let me know. I would appreciate any help.
Aug 8 '08 #1
9 1815
code green
1,726 Expert 1GB
You obviously do not have error_reporting switched on because this [PHP]if ($officer_show == YES)[/PHP] would throw a warning about an undefined constant. It should be [PHP]if ($officer_show == "YES")[/PHP] But get rid of this string comparison and use booleans: true, false or 1,0.
It is much cleaner [PHP]if($officer_show)[/PHP] Talking of clean. Try to seperate your HTML and PHP.
I write php in .php files that 'include' HTML code in seperate .html files.
Your code looks too cluttered to study
Aug 8 '08 #2
HI, I did turn on error reporting, as explained in one sticky post. I just forgot to update my script that I posted. I did get that error and fixed that one. I will try changing it as specified. Thanks for your response.
Aug 10 '08 #3
The tip you offered didn't seem to make a difference.



I also am getting an notice with the code below. the warnings are:

This one I get if I'm not loged in. Is there a way to get rid of it, other than logging in (with error reporting on).
Expand|Select|Wrap|Line Numbers
  1. Notice: Undefined index: 'auth' in /home/content/m/a/t/mattjenne***/html/members/sub_officers3.php on line 126
  2.  
  3. Notice: Undefined variable: display_block in /home/content/m/a/t/mattjenne***/html/members/sub_officers3.php on line 148
  4.  
Expand|Select|Wrap|Line Numbers
  1. //starting at line 126//
  2.             if($_SESSION['auth']['status'] == 1){
  3.                 // do stuff here
  4. $display_block .= "
  5. <tr>
  6.  <td>$sub_office</td>
  7.  <td>$fname $lname</td>
  8.  <td>$hphone / $cphone</td>
  9.  <td>$eml</td>
  10.  <td>$adress, $cty, $st $zp</td>
  11.  <td>$sub_name</td>
  12. </tr>"; 
  13.             }
  14.  
Aug 10 '08 #4
Atli
5,058 Expert 4TB
Hi. welcome to Bytes!

I'm guessing a lot of your problems are caused by that monster of a first line.
It includes a few if statements, some HTML and last, but not least, a single-line comment, which will comment out everything behind it.

Copying your code into my IDE, I see half the first line commented out, and an extra closing curly-brace.

Try re-formatting that first line into something readable. If it still gives you problems, post it here and we'll take a look.
Aug 10 '08 #5
Hi, I noticed when I copied the script that the post came out different than I typed it. What is showed as one big line was origionally written as 25+ lines. I have tried to make a couple of changes, but no luck. I have uploaded the script in a text file to my website. If you would check it out it would be helpful. The file is at http://www.pomonagrange.org/helpme/sub_officers2.txt. I would appreciate it if you could look it over. This is the whole file, not just an a portion. Thanks for the help.
Aug 11 '08 #6
Atli
5,058 Expert 4TB
Just posting your code here to make the thread easier to follow. People are often scared of by external links. Hope you don't mind.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. session_start();
  4.  
  5. include ('./config/db.php');
  6.  
  7. $sub_name = $_GET['sub_name'];
  8.  
  9. //make connection to dbase
  10. $connection = @mysql_connect($server, $dbusername, $dbpassword)
  11.                 or die(mysql_error());
  12.  
  13. $db = @mysql_select_db($db_name,$connection)
  14.                 or die(mysql_error());
  15. $sql = "SELECT `sub_name`, `pom_name`, `maxdegree`, `pom_office`, `sub_office`, `lname`, `fname`, `minitial`, `maidenname`, `address`, `city`, `state`, `zip`, `homephone`, `cellphone`, `email`,
  16. (SELECT 
  17.   CASE
  18.    WHEN `sub_office` = 'Master - President' THEN 1
  19.    WHEN `sub_office` = 'Overseer - Vice President' THEN 2
  20.    WHEN `sub_office` = 'Lecturer - Program Director' THEN 3
  21.    WHEN `sub_office` = 'Steward' THEN 4
  22.    WHEN `sub_office` = 'Assistant Steward' THEN 5
  23.    WHEN `sub_office` = 'Lady Assistant Steward' THEN 6
  24.    WHEN `sub_office` = 'Chaplain' THEN 7
  25.    WHEN `sub_office` = 'Treasurer' THEN 8
  26.    WHEN `sub_office` = 'Building Treasurer' THEN 9
  27.    WHEN `sub_office` = 'Secretary' THEN 10
  28.    WHEN `sub_office` = 'Gate Keeper' THEN 11
  29.    WHEN `sub_office` = 'Flora' THEN 12
  30.    WHEN `sub_office` = 'Pomona' THEN 13
  31.    WHEN `sub_office` = 'Ceres' THEN 14
  32.    WHEN `sub_office` = 'Executive Committee' THEN 15
  33.    WHEN `sub_office` = 'Pianist' THEN 16
  34.    WHEN `sub_office` = 'Leadership' THEN 17
  35.    WHEN `sub_office` = 'Membership' THEN 18
  36.    WHEN `sub_office` = 'Legislative' THEN 19
  37.    WHEN `sub_office` = 'Family Activities' THEN 20
  38.    WHEN `sub_office` = 'Community Service' THEN 21
  39.    WHEN `sub_office` = 'Fun Committee' THEN 22
  40.    ELSE 23
  41.   END) as sort
  42. FROM MembersTable WHERE `sub_name` = '".$sub_name."'
  43.  
  44. ORDER BY sort ASC";
  45.  
  46. $result = @mysql_query($sql,$connection) or die(mysql_error());
  47.  
  48. while ($row = mysql_fetch_array($result)) {
  49.  
  50. if (!$row["sub_name"]) { $sub_name="&nbsp"; } 
  51.    else { $sub_name = " ".$row['sub_name']."\n"; } 
  52.  
  53. if (!$row["pom_name"]) { $pom_name="&nbsp"; } 
  54.   else { $pom_name = " ".$row['pom_name']."\n"; } 
  55.  
  56. if (!$row["maxdegree"]) { $maxdegree="&nbsp"; } 
  57.   else { $maxdegree = " ".$row['maxdegree']."\n"; } 
  58.  
  59. if (!$row["pom_office"]) { $pom_office="&nbsp"; } 
  60.   else { $pom_office = " ".$row['pom_office']."\n"; } 
  61.  
  62. if (!$row["sub_office"]) { $sub_office="&nbsp"; } 
  63.   else { $sub_office = " ".$row['sub_office']."\n"; } 
  64.  
  65. if (!$row["lname"]) { $lname="&nbsp"; } 
  66.   else { $lname = " ".$row['lname']."\n"; } 
  67.  
  68. if (!$row["fname"]) { $fname="&nbsp"; } 
  69.   else { $fname = " ".$row['fname']."\n"; } 
  70.  
  71. if (!$row["minitial"]) { $minitial="&nbsp"; } 
  72.   else { $minitial = " ".$row['minitial']."\n"; } 
  73.  
  74. if (!$row["maidenname"]) { $maidenname="&nbsp"; } 
  75.   else { $maidenname = " ".$row['maidenname']."\n"; } 
  76.  
  77. if (!$row["address"]) { $address=""; } 
  78.   else { $address = " ".$row['address']."\n"; } 
  79.  
  80. if (!$row["city"]) { $city="&nbsp"; } 
  81.   else { $city = " ".$row['city']."\n"; } 
  82.  
  83. if (!$row["state"]) { $state="&nbsp"; } 
  84.   else { $state = " ".$row['state']."\n"; } 
  85.  
  86. if (!$row["zip"]) { $zip="&nbsp"; } 
  87.   else { $zip = " ".$row['zip']."\n"; } 
  88.  
  89. if (!$row["homephone"]) { $homephone="&nbsp"; } 
  90.   else { $homephone = " ".$row['homephone']."\n"; } 
  91.  
  92. if (!$row["cellphone"]) { $cellphone="&nbsp"; } 
  93.   else { $cellphone = " ".$row['cellphone']."\n"; } 
  94.  
  95. if (!$row["email"]) { $email="&nbsp;"; } 
  96.   else { $email = " <a href=\"mailto:".$row['email']."\">".$row['email']."</a>\n"; } 
  97.  
  98.  
  99. if ($row["sub_office"] == 'Master - President'){$officer_show = "YES";}
  100. ELSEIF($row["sub_office"] == 'Overseer - Vice President'){$officer_show = "YES";}
  101. ELSEIF($row["sub_office"] == 'Lecturer - Program Director'){$officer_show = "YES";}
  102. ELSEIF($row["sub_office"] == 'Secretery'){$officer_show = "YES";}
  103. ELSE{$officer_show = "NO";}
  104.  
  105.  
  106.             if($_SESSION['auth']['status'] == 1){$show_all = "YES";}ELSE{$show_all = "NO";}
  107.  
  108. if ($officer_show == 'YES'){
  109. $homephone = $homephone;
  110. $cellphone = $cellphone;
  111. $address = $address;
  112. $city = $city;
  113. $state = $state;
  114. $zip = $zip;
  115. $email = $email;
  116. }
  117. ELSEIF($show_all == 'YES'){
  118. $homephone = $homephone;
  119. $cellphone = $cellphone;
  120. $address = $address;
  121. $city = $city;
  122. $state = $state;
  123. $zip = $zip;
  124. $email = $email;}
  125. ELSE
  126. {
  127. $homephone = "&nbsp;";
  128. $cellphone = "&nbsp;";
  129. $address = "&nbsp;";
  130. $city = "&nbsp;";
  131. $state = "&nbsp;";
  132. $zip = "&nbsp;";
  133. $email = "&nbsp;";
  134. }
  135.  
  136. $display_block .= "
  137. <tr>
  138.  <td>$sub_office</td>
  139.  <td>$fname $lname</td>
  140.  <td>$hphone / $cphone</td>
  141.  <td>$eml</td>
  142.  <td>$adress, $cty, $st $zp</td>
  143.  <td>$sub_name</td>
  144. </tr>"; 
  145.  
  146. $title = "<title>Officers of the ".$sub_name." Subordinate Grange</title>";
  147. ?>
  148.  
  149. <? include("./config/header.php"); ?>
  150.  
  151. </head>
  152.  
  153. <body>
  154. <? include $_SERVER['DOCUMENT_ROOT']."/glist.txt"; ?>
  155.  
  156.  
  157. <table width="85%" border="1" class="main"><tbody>
  158. <tr><td colspan="6"><h2>Officers of <? echo "$sub_name"; ?> Subordinate Grange</h2></td></tr>
  159.  
  160. <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>
  161.  
  162. <? echo "$display_block"; ?>
  163.  
  164. <tr><td colspan="6"><!-- C. FOOTER AREA -->      
  165.  
  166.  
  167.     <div class="footer">
  168.       <? include ('./config/footerinfo.php'); ?>
  169.     </div>      </td></tr>
  170.  
  171. </tbody></table>
  172.  
  173.  
  174. </body>
  175. </html>
  176.  
I'll have a look at it, see if I can spot any problems.
Aug 12 '08 #7
Atli
5,058 Expert 4TB
What is the `sub_name` value you are using to filter the SQL results with?

The main problem there would be the way you handle the data. The flood of if statements is a testament to that.
You are fetching all the data from the database, and having PHP sort through it, which is something you should never do.

Before you execute your query, you should figure out what data should be displayed and select only that. Tailor your SQL to fit the situation, don't select everything and filter the data once it has been fetched.

Consider this example:
Expand|Select|Wrap|Line Numbers
  1. /***
  2.  *  Show publicly available data
  3.  ***/
  4. // Set up the roles that should be visible to the public
  5. $rolesToShow = array("President", "Gardner");
  6. $roles = "'". implode("', '", $rolesToShow) ."'");
  7.  
  8. // Create and execute the query
  9. $sql = "SELECT name, email, phone FROM userTable WHERE role IN($roles)";
  10. $result = mysql_query($sql);
  11.  
  12. // Display the public data
  13. while($row = mysql_fetch_row($result)) {
  14.   # Show data
  15. }
  16.  
  17. /***
  18.  * Show member specific data
  19.  ***/
  20. // Create the SQL query based on the user's status.
  21. if($_SESSION['User']['status'] == 1) {
  22.   $sql = "SELECT name, email phone FROM userTable WHERE role NOT IN($roles)";
  23. }
  24. else {
  25.   $sql = "SELECT name FROM userTable WHERE role NOT IN($roles)";
  26. }
  27.  
  28. // Execute the query and display the results
  29. $result = mysql_query($sql);
  30.  
  31. while($row = mysql_fetch_assoc($result)) {
  32.   // Set these based on whether the data was fetched or not
  33.   // The (bool ? true : false) format is basically a compact if statement.
  34.   $name = $row['name'];
  35.   $email = (isset($row['email']) ? $row['email'] : "&nbsp");
  36.   $phone = (isset($row['phone ']) ? $row['phone '] : "&nbsp");
  37.  
  38.   # Display data
  39. }
  40.  
This would show all visitors the President and Gardner roles, but hide everything but the names from all other roles, unless you are logged in.
Aug 12 '08 #8
Hey Thanks for the response. This club is county wide with some local groups within the county organization. The row `sub_name` is to determine which 'sub division' they are a member of. This variable will be passed using the GET method from another page.

I will try the suggestion you made.I was going to try multiple sql statements, but wasn't sure of how exactly to go about it as I am fairly new to php programming.

Also with this, is there a way to sort the names in a certain order according to their office. I had this in the file that I uploaded, but with splitting the sql statements, how could I get that to work.

Thanks again for your reply.
Aug 12 '08 #9
Hey just to let you know I finally got this script working. Thanks for your help. If you guys hadn't helped I wouldn't have gotten it working.
Aug 14 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Rich | last post by:
i have a web page that uses a javascript function to show/hide some info using css "visibile" "hidden" attributes of "id". the js was a free script that i modified for my use. works great. to...
10
by: David | last post by:
Hi everyone, Hoping there are some .js/browser experts out there that can help with this weird problem. I have made a swap div routine and applied the events to menu buttons with a closer...
2
by: MOHSEN KASHANI | last post by:
Hi, I am trying to hide some form elements in a form by default and show/hide depending on which radio button is clicked. This is what I have but it is not working: <head> <style> ..noshow {...
4
by: jerryyang_la1 | last post by:
I've found this script that allows be to hide/show form elements.. <script language="JavaScript"><!-- var toggle = true; function show(object) { if (document.layers && document.layers)...
4
by: bridgemanusa | last post by:
Hi All: I have a very long page of html that I want to take portions and hide them in divs, then show when a link is clicked. I have the hide show part working when the link is clicked, however...
3
by: Merlin | last post by:
Hi there, I am trying to create a form with an dynamic field that can be shown or hidden. As I saw for example on google it is possible with JS to show a layer and move the content underneath...
1
by: asilverpeach | last post by:
Hey Guys! Found some great scripts here on this topic but have to make to changes to the code that I can't seem to figure out. First, In the following code clicking on the headers shows the...
3
by: timplx | last post by:
Hello all, New to javascript and have never worked with programming languages like c++, so my logic in some of these statements might be incorrect or redundant Got a problem with my page......
1
oranoos3000
by: oranoos3000 | last post by:
hi would you please help me i have a online shopping center that i show pictures of the my product in home page. in the InterExplorer pictures is shown correctly but in Firefox browser is shown...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.