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 = " ";$cphon e = " ";$adres s = " ";$c ty = " ";$s t = " ";$z p = " ";$e ml = " ";} 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 = " ";
$cphone = " ";
$adress = " ";
$cty = " ";
$st = " ";
$zp = " ";
$eml = " ";
}
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.
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
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.
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). -
Notice: Undefined index: 'auth' in /home/content/m/a/t/mattjenne***/html/members/sub_officers3.php on line 126
-
-
Notice: Undefined variable: display_block in /home/content/m/a/t/mattjenne***/html/members/sub_officers3.php on line 148
-
-
//starting at line 126//
-
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>";
-
}
-
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.
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.
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. -
<?php
-
-
session_start();
-
-
include ('./config/db.php');
-
-
$sub_name = $_GET['sub_name'];
-
-
//make connection to dbase
-
$connection = @mysql_connect($server, $dbusername, $dbpassword)
-
or die(mysql_error());
-
-
$db = @mysql_select_db($db_name,$connection)
-
or die(mysql_error());
-
$sql = "SELECT `sub_name`, `pom_name`, `maxdegree`, `pom_office`, `sub_office`, `lname`, `fname`, `minitial`, `maidenname`, `address`, `city`, `state`, `zip`, `homephone`, `cellphone`, `email`,
-
(SELECT
-
CASE
-
WHEN `sub_office` = 'Master - President' THEN 1
-
WHEN `sub_office` = 'Overseer - Vice President' THEN 2
-
WHEN `sub_office` = 'Lecturer - Program Director' THEN 3
-
WHEN `sub_office` = 'Steward' THEN 4
-
WHEN `sub_office` = 'Assistant Steward' THEN 5
-
WHEN `sub_office` = 'Lady Assistant Steward' THEN 6
-
WHEN `sub_office` = 'Chaplain' THEN 7
-
WHEN `sub_office` = 'Treasurer' THEN 8
-
WHEN `sub_office` = 'Building Treasurer' THEN 9
-
WHEN `sub_office` = 'Secretary' THEN 10
-
WHEN `sub_office` = 'Gate Keeper' THEN 11
-
WHEN `sub_office` = 'Flora' THEN 12
-
WHEN `sub_office` = 'Pomona' THEN 13
-
WHEN `sub_office` = 'Ceres' THEN 14
-
WHEN `sub_office` = 'Executive Committee' THEN 15
-
WHEN `sub_office` = 'Pianist' THEN 16
-
WHEN `sub_office` = 'Leadership' THEN 17
-
WHEN `sub_office` = 'Membership' THEN 18
-
WHEN `sub_office` = 'Legislative' THEN 19
-
WHEN `sub_office` = 'Family Activities' THEN 20
-
WHEN `sub_office` = 'Community Service' THEN 21
-
WHEN `sub_office` = 'Fun Committee' THEN 22
-
ELSE 23
-
END) as sort
-
FROM MembersTable WHERE `sub_name` = '".$sub_name."'
-
-
ORDER BY sort ASC";
-
-
$result = @mysql_query($sql,$connection) or die(mysql_error());
-
-
while ($row = mysql_fetch_array($result)) {
-
-
if (!$row["sub_name"]) { $sub_name=" "; }
-
else { $sub_name = " ".$row['sub_name']."\n"; }
-
-
if (!$row["pom_name"]) { $pom_name=" "; }
-
else { $pom_name = " ".$row['pom_name']."\n"; }
-
-
if (!$row["maxdegree"]) { $maxdegree=" "; }
-
else { $maxdegree = " ".$row['maxdegree']."\n"; }
-
-
if (!$row["pom_office"]) { $pom_office=" "; }
-
else { $pom_office = " ".$row['pom_office']."\n"; }
-
-
if (!$row["sub_office"]) { $sub_office=" "; }
-
else { $sub_office = " ".$row['sub_office']."\n"; }
-
-
if (!$row["lname"]) { $lname=" "; }
-
else { $lname = " ".$row['lname']."\n"; }
-
-
if (!$row["fname"]) { $fname=" "; }
-
else { $fname = " ".$row['fname']."\n"; }
-
-
if (!$row["minitial"]) { $minitial=" "; }
-
else { $minitial = " ".$row['minitial']."\n"; }
-
-
if (!$row["maidenname"]) { $maidenname=" "; }
-
else { $maidenname = " ".$row['maidenname']."\n"; }
-
-
if (!$row["address"]) { $address=""; }
-
else { $address = " ".$row['address']."\n"; }
-
-
if (!$row["city"]) { $city=" "; }
-
else { $city = " ".$row['city']."\n"; }
-
-
if (!$row["state"]) { $state=" "; }
-
else { $state = " ".$row['state']."\n"; }
-
-
if (!$row["zip"]) { $zip=" "; }
-
else { $zip = " ".$row['zip']."\n"; }
-
-
if (!$row["homephone"]) { $homephone=" "; }
-
else { $homephone = " ".$row['homephone']."\n"; }
-
-
if (!$row["cellphone"]) { $cellphone=" "; }
-
else { $cellphone = " ".$row['cellphone']."\n"; }
-
-
if (!$row["email"]) { $email=" "; }
-
else { $email = " <a href=\"mailto:".$row['email']."\">".$row['email']."</a>\n"; }
-
-
-
if ($row["sub_office"] == 'Master - President'){$officer_show = "YES";}
-
ELSEIF($row["sub_office"] == 'Overseer - Vice President'){$officer_show = "YES";}
-
ELSEIF($row["sub_office"] == 'Lecturer - Program Director'){$officer_show = "YES";}
-
ELSEIF($row["sub_office"] == 'Secretery'){$officer_show = "YES";}
-
ELSE{$officer_show = "NO";}
-
-
-
if($_SESSION['auth']['status'] == 1){$show_all = "YES";}ELSE{$show_all = "NO";}
-
-
if ($officer_show == 'YES'){
-
$homephone = $homephone;
-
$cellphone = $cellphone;
-
$address = $address;
-
$city = $city;
-
$state = $state;
-
$zip = $zip;
-
$email = $email;
-
}
-
ELSEIF($show_all == 'YES'){
-
$homephone = $homephone;
-
$cellphone = $cellphone;
-
$address = $address;
-
$city = $city;
-
$state = $state;
-
$zip = $zip;
-
$email = $email;}
-
ELSE
-
{
-
$homephone = " ";
-
$cellphone = " ";
-
$address = " ";
-
$city = " ";
-
$state = " ";
-
$zip = " ";
-
$email = " ";
-
}
-
-
$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>";
-
}
-
-
$title = "<title>Officers of the ".$sub_name." Subordinate Grange</title>";
-
?>
-
-
<? include("./config/header.php"); ?>
-
-
</head>
-
-
<body>
-
<? include $_SERVER['DOCUMENT_ROOT']."/glist.txt"; ?>
-
-
-
<table width="85%" border="1" class="main"><tbody>
-
<tr><td colspan="6"><h2>Officers of <? echo "$sub_name"; ?> Subordinate Grange</h2></td></tr>
-
-
<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>
-
-
<? echo "$display_block"; ?>
-
-
<tr><td colspan="6"><!-- C. FOOTER AREA -->
-
-
-
<div class="footer">
-
<? include ('./config/footerinfo.php'); ?>
-
</div> </td></tr>
-
-
</tbody></table>
-
-
-
</body>
-
</html>
-
I'll have a look at it, see if I can spot any problems.
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: -
/***
-
* Show publicly available data
-
***/
-
// Set up the roles that should be visible to the public
-
$rolesToShow = array("President", "Gardner");
-
$roles = "'". implode("', '", $rolesToShow) ."'");
-
-
// Create and execute the query
-
$sql = "SELECT name, email, phone FROM userTable WHERE role IN($roles)";
-
$result = mysql_query($sql);
-
-
// Display the public data
-
while($row = mysql_fetch_row($result)) {
-
# Show data
-
}
-
-
/***
-
* Show member specific data
-
***/
-
// Create the SQL query based on the user's status.
-
if($_SESSION['User']['status'] == 1) {
-
$sql = "SELECT name, email phone FROM userTable WHERE role NOT IN($roles)";
-
}
-
else {
-
$sql = "SELECT name FROM userTable WHERE role NOT IN($roles)";
-
}
-
-
// Execute the query and display the results
-
$result = mysql_query($sql);
-
-
while($row = mysql_fetch_assoc($result)) {
-
// Set these based on whether the data was fetched or not
-
// The (bool ? true : false) format is basically a compact if statement.
-
$name = $row['name'];
-
$email = (isset($row['email']) ? $row['email'] : " ");
-
$phone = (isset($row['phone ']) ? $row['phone '] : " ");
-
-
# Display data
-
}
-
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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.
|
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;
}
|
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';
|
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
| |
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....
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |