| | |
show club presidents info hide everyone else's
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jun 2008
Posts: 62
Reputation:
Solved Threads: 3
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.
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.
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)
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 = " "; $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>"; } }
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
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.
•
•
Join Date: Aug 2008
Posts: 48
Reputation:
Solved Threads: 4
Well, I don't know all your database, but here's a sample script I would use:
php Syntax (Toggle Plain Text)
if (!logged_in) { $query1 = mysql_query("SELECT * FROM membersinfo WHERE id = 'president'"); while ($row = mysql_fetch array($sql)) { echo "<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>"; } } elseif (logged_in) { $query2 = mysql_query("SELECT * FROM membersinfo"); while ($row = mysql_fetch array($sql)) { echo "<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>"; } }
Last edited by Demiloy; Aug 7th, 2008 at 11:00 am.
•
•
Join Date: Jun 2008
Posts: 62
Reputation:
Solved Threads: 3
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.
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.
•
•
Join Date: Aug 2008
Posts: 48
Reputation:
Solved Threads: 4
In which case, you could change the query. Under the if(!logged_in) part, after the first query:
That should do the trick.
php Syntax (Toggle Plain Text)
$names = mysql_query("SELECT name FROM members WHERE id != 'president'"); while ($info = mysql_fetch array($names)) { // echo names } //continue on with elseif
That should do the trick.
Last edited by Demiloy; Aug 7th, 2008 at 11:16 pm.
•
•
Join Date: Jun 2008
Posts: 62
Reputation:
Solved Threads: 3
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.
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.
•
•
Join Date: Jun 2008
Posts: 62
Reputation:
Solved Threads: 3
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:
Of coarse I added a few things to try to make it work for me (eg. sql connect info ect.).
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)
<?php session_start(); include ('./config/db.php'); $sub_name = $_GET['sub_name']; $connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error()); $db = @mysql_select_db($db_name,$connection) or die(mysql_error()); /*** * Show publicly available data ***/ // Set up the roles that should be visible to the public $rolesToShow = array("Master - President", "Overseer - Vice President", "Lecturer - Program Director", "Secretary"); $roles = "'". implode("', '", $rolesToShow)."'"; // Create and execute the query $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)"; $result = mysql_query($sql,$connection) or die(mysql_error()); // Display the public data while($row = mysql_fetch_row($result)) { # Show data $fname = $row['fname']; $lname = $row['lname']; $sub_office = $row['sub_office']; $email = (isset($row['email']) ? $row['email'] : " "); $homephone = (isset($row['homephone']) ? $row['homephone'] : " "); $cellphone = (isset($row['cellphone']) ? $row['cellphone'] : " "); $address = (isset($row['address']) ? $row['address'] : " "); $city = (isset($row['city']) ? $row['city'] : " "); $state = (isset($row['state']) ? $row['state'] : " "); $zip = (isset($row['zip']) ? $row['zip'] : " "); } /*** * Show member specific data ***/ // Create the SQL query based on the user's status. if($_SESSION['User']['status'] == 1) { $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)"; } else { $sql2 = "SELECT fname, lname, sub_office FROM MembersTable WHERE sub_name = '".$sub_name."' AND '".$sub_office."' NOT IN($roles)"; } // Execute the query and display the results $result2 = mysql_query($sql2,$connection) or die(mysql_error()); while($row = mysql_fetch_assoc($result2)) { // Set these based on whether the data was fetched or not // The (bool ? true : false) format is basically a compact if statement. $fname = $row['fname']; $lname = $row['lname']; $sub_office = $row['sub_office']; $email = (isset($row['email']) ? $row['email'] : " "); $homephone = (isset($row['homephone']) ? $row['homephone'] : " "); $cellphone = (isset($row['cellphone']) ? $row['cellphone'] : " "); $address = (isset($row['address']) ? $row['address'] : " "); $city = (isset($row['city']) ? $row['city'] : " "); $state = (isset($row['state']) ? $row['state'] : " "); $zip = (isset($row['zip']) ? $row['zip'] : " "); # Display data $display_block .= " <tr> <td>$sub_office</td> <td>$fname $lname</td> <td>$homephone / $cellphone</td> <td>$email</td> <td>$address, $city, $state $zip</td> <td>$sub_name</td> </tr>"; } $title = "<title>Officers of the ".$sub_name." Subordinate Grange</title>"; ?> <? include("./config/header.php"); ?> </head> <body> <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>
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.
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
I only found one type of thing wrong on this page, all of your
$zip = (isset($row['zip']) ? $row['zip'] : " ");
lines have an unmatched bracket ) on the end of them.
So I changed them to this
And played around with the rest of the code some too ... but no promises
$zip = (isset($row['zip']) ? $row['zip'] : " ");
lines have an unmatched bracket ) on the end of them.
So I changed them to this
PHP Syntax (Toggle Plain Text)
$zip = ( isset($row['zip'] ) ? $row['zip'] : " ";
PHP Syntax (Toggle Plain Text)
<?php session_start(); include( './config/db.php' ); $sub_name = $_GET['sub_name']; $link = @mysql_connect( $server, $dbusername, $dbpassword ) or die(mysql_error()); $db = @mysql_select_db( $db_name ) or die(mysql_error()); /*** * Show publicly available data ***/ // Set up the roles that should be visible to the public $rolesToShow = array( "Master - President", "Overseer - Vice President", "Lecturer - Program Director", "Secretary" ); $roles = "'".implode( "', '", $rolesToShow )."'"; // Create and execute the query $sql = "SELECT * FROM `MembersTable` WHERE sub_name='$sub_name' AND '$sub_office' IN($roles)"; $result = mysql_query( $sql ) or die( mysql_error() ); // Display the public data while( $row = mysql_fetch_row( $result ) ) { # Show data $fname = $row['fname']; $lname = $row['lname']; $sub_office = $row['sub_office']; $email = ( isset($row['email'] ) ? $row['email'] : " "; $homephone = ( isset($row['homephone'] ) ? $row['homephone'] : " "; $cellphone = ( isset($row['cellphone'] ) ? $row['cellphone'] : " "; $address = ( isset($row['address'] ) ? $row['address'] : " "; $city = ( isset($row['city'] ) ? $row['city'] : " "; $state = ( isset($row['state'] ) ? $row['state'] : " "; $zip = ( isset($row['zip'] ) ? $row['zip'] : " "; } /*** * Show member specific data ***/ // Create the SQL query based on the user's status. if( $_SESSION['User']['status'] == 1 ) { $sql2 = "SELECT * FROM MembersTable WHERE sub_name = '$sub_name' AND '$sub_office' NOT IN($roles)"; } else { $sql2 = "SELECT fname, lname, sub_office FROM MembersTable WHERE sub_name = '$sub_name' AND '$sub_office' NOT IN($roles)"; } // Execute the query and display the results $result2 = mysql_query( $sql2 ) or die( mysql_error() ); while ( $row = mysql_fetch_assoc( $result2 ) ) { // Set these based on whether the data was fetched or not // The (bool ? true : false) format is basically a compact if statement. $fname = $row['fname']; $lname = $row['lname']; $sub_office = $row['sub_office']; $email = ( isset($row['email'] ) ? $row['email'] : " "; $homephone = ( isset($row['homephone'] ) ? $row['homephone'] : " "; $cellphone = ( isset($row['cellphone'] ) ? $row['cellphone'] : " "; $address = ( isset($row['address'] ) ? $row['address'] : " "; $city = ( isset($row['city'] ) ? $row['city'] : " "; $state = ( isset($row['state'] ) ? $row['state'] : " "; $zip = ( isset($row['zip'] ) ? $row['zip'] : " "; # Display data $display_block .= <<<ENDLINE <tr> <td>$sub_office</td> <td>$fname $lname</td> <td>$homephone / $cellphone</td> <td>$email</td> <td>$address, $city, $state $zip</td> <td>$sub_name</td> </tr> ENDLINE; } $title = "<title>Officers of the $sub_name Subordinate Grange</title>"; ?> <? include("./config/header.php"); ?> </head> <body> <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>
Last edited by langsor; Aug 12th, 2008 at 7:22 pm.
•
•
Join Date: Jun 2008
Posts: 62
Reputation:
Solved Threads: 3
This is still a no go. also if you look at
$zip = (isset($row['zip']) ? $row['zip'] : " ");
They are not mis matched.
Oh well, I'll keep fooling with it until I get it figured out.
$zip = (isset($row['zip']) ? $row['zip'] : " ");
They are not mis matched.
Oh well, I'll keep fooling with it until I get it figured out.
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.
![]() |
Other Threads in the PHP Forum
- Previous Thread: creating a search form with multiple options, like the search form used on this site?
- Next Thread: prob installing .... help is needed
| Thread Tools | Search this Thread |
ajax apache api array beginner binary body broken cakephp checkbox class cms code cron curl database date date/time display dynamic echo email error file files folder form forms function functions gc_maxlifetime global google host href htaccess html image include insert integration ip java javascript joomla limit link list login loop mail memmory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php problem query radio random recourse recursion regex registrationform remote script search seo server sessions sms soap source space sql static syntax system table tutorial update upload url validator variable video web webdesign wordpress xml youtube





