473,785 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

show club presidents info hide everyone else's

6 New Member
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_s how = "NO";} if ($officer_show == YES){$hphone = $homephone;$cph one = $cellphone;$adr ess = $address;$cty = $city;$st = $state;$zp = $zip;$eml = $email;}ELSE{$h phone = "&nbsp;";$cphon e = "&nbsp;";$adres s = "&nbsp;";$c ty = "&nbsp;";$s t = "&nbsp;";$z p = "&nbsp;";$e ml = "&nbsp;";} if($_SESSION['auth']['status'] == 1){ // do stuff here$display_bl ock .= "<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_s how = "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 1835
code green
1,726 Recognized Expert Top Contributor
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_sho w)[/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
PomonaGrange
6 New Member
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
PomonaGrange
6 New Member
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 Recognized Expert Expert
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
PomonaGrange
6 New Member
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 Recognized Expert Expert
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 Recognized Expert Expert
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
PomonaGrange
6 New Member
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
PomonaGrange
6 New Member
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
2214
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 make it even better though, i need to print just the info identified by the span tag's "id". I'm not sure how to do that. here's more info: the page has several "id" spans that are initially hidden, when the page first loads. there are some links...
10
3213
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 layer behind the menus. The closer div has a lower index than the submenu divs so it appears behind them. The closer div contains a transparent gif with an event applied to it to close all of the divs when moused over.
2
12190
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 { display: none; }
4
8011
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) document.layers.visibility = 'visible'; else if (document.all) { document.all.style.visibility = 'visible';
4
4232
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 I would really like to use linked images instead to do the following: - When open.gif is clicked, the contents of the div show and open.gif is swapped with close.gif - subsequently, when close.gif is clicked, the div contents get hidden
3
6404
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 that layer further down uppon showing this layer. When a person closes that layer the content underneath the layer moves up again and closes the empty space. How is this possible? I am playing around with some code I am posting with this thread....
1
16759
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 div information. I want a nested show hide element though. So when you click on "Do you have carpets to be cleaned?" Small Rooms & Medium Rooms appears (that I got working) But Then when you click on Small rooms or medium rooms i want the three lines...
3
3356
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... using java and external css to show/hide items on the same click. I found a script that uses the getElementById function to adjust the display style of a div id. I have utilized this to show four ids in the same space on my page. Some ids start with...
1
3812
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 properties alt in img tag istead of picture . place of the pictures is saved in the database(my database is with mysql) and in home page i fetch properties of the product and address of place that pictures is located output of the code in the...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10329
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10152
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.