DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   show club presidents info hide everyone else's (http://www.daniweb.com/forums/thread139040.html)

PomonaGrange Aug 12th, 2008 10:17 pm
Re: show club presidents info hide everyone else's
 
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!

langsor Aug 13th, 2008 4:19 am
Re: show club presidents info hide everyone else's
 
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
<?php

include( './config/db.php' );
$sub_name = $_GET['sub_name']; // If it's a form value, you probably want to use $_POST['sub_name'] with <form method="POST">

$officers = array( "President", "Vice President", "Secretery" ); // edit to suite your needs ...

session_start();
$session = ( $_SESSION['auth']['status'] == 1 ) ? TRUE : FALSE; // or ? ... ( $_SESSION['User']['status'] == 1 )

$link = @mysql_connect( $host, $user, $pass ) or die( mysql_error() );
@mysql_select_db( $dbase ) or die( mysql_error() );
// make sure these are the names of the fields in your database, change them in
// the $sql query `email` (etc) and the $obj->email values (bellow) if they are not ...
$sql = "SELECT `fname`, `lname`, `sub_office`, `email`, `homephone`, `cellphone`, `address`, `city`, `state`, `zip` FROM `MembersTable` WHERE sub_name='$sub_name'";
// You can just use this, if thesse are all or most of the values in the table ...
// $sql = "SELECT * FROM `MembersTable` WHERE sub_name='$sub_name'";
$result = mysql_query( $sql ) or die( mysql_error() );

$html = '';
while ( $obj = mysql_fetch_object( $result ) ) {
  $html .= <<<ENDHTML
    <tr>
      <td>$obj->sub_office</td>
      <td>$obj->fname $obj->lname</td>
ENDHTML;
  if ( $session || in_array( $obj->sub_office, $officers ) ) {
    $html .=<<<ENDHTML
      <td>$$obj->hphone / $cphone</td>
      <td>$$obj->email</td>
      <td>$$obj->address, $$obj->cty, $$obj->state $$obj->zip</td>
      <td>$$obj->sub_name</td>
ENDHTML;
  }
  $html .= "    <\tr>\n";
}

$title = "<title>Officers of the $sub_name Subordinate Grange</title>";

?>
<?php 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>
<?php print $html; ?>
    <tr>
      <td colspan="6"><!-- C. FOOTER AREA -->
        <div class="footer">
<?php include ('./config/footerinfo.php'); ?>
        </div></td>
    </tr>
  </tbody>
</table>
</body>
</html>

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

Ciao

PomonaGrange Aug 13th, 2008 11:44 am
Re: show club presidents info hide everyone else's
 
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.

<?php

include( './config/db.php' );

$sub_name = $_GET['sub_name']; // If it's a form value, you probably want to use $_POST['sub_name'] with <form method="POST">

$officers = array( "Master - President", "Overseer - Vice President", "Secretery", "Lecturer - Program Director" ); // edit to suite your needs ...

session_start();
$session = ( $_SESSION['auth']['status'] == 1 ) ? TRUE : FALSE; // or ? ... ( $_SESSION['User']['status'] == 1 )

$link = @mysql_connect( $server, $dbusername, $dbpassword ) or die( mysql_error() );
@mysql_select_db( $db_name ) or die( mysql_error() );
// make sure these are the names of the fields in your database, change them in
// the $sql query `email` (etc) and the $obj->email values (bellow) if they are not ...

$sql = "SELECT `fname`, `lname`, `sub_office`, `email`, `homephone`, `cellphone`, `address`, `city`, `state`, `zip`,
(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";

// You can just use this, if thesse are all or most of the values in the table ...
// $sql = "SELECT * FROM `MembersTable` WHERE sub_name='$sub_name'";
$result = mysql_query( $sql ) or die( mysql_error() );

$html = '';
while ( $obj = mysql_fetch_object( $result ) ) {
  $html .= <<<ENDHTML
    <tr>
      <td>$obj->sub_office</td>
      <td>$obj->fname $obj->lname</td>
ENDHTML;
  if ( $session || in_array( $obj->sub_office, $officers ) ) {
    $html .=<<<ENDHTML
      <td>$obj->homephone / $obj->cellphone</td>
      <td>$obj->email</td>
      <td>$obj->address, $obj->city, $obj->state $obj->zip</td>
      <td>$obj->sub_name</td>
ENDHTML;
  }
  $html .= "    <\tr>\n";
}

$title = "<title>Officers of the $sub_name Subordinate Grange</title>";

?>
<?php 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>
<?php print $html; ?>
    <tr>
      <td colspan="6"><!-- C. FOOTER AREA -->
        <div class="footer">
<?php include ('./config/footerinfo.php'); ?>
        </div></td>
    </tr>
  </tbody>
</table>
</body>
</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.

langsor Aug 13th, 2008 1:31 pm
Re: show club presidents info hide everyone else's
 
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
$html = '';
while ( $obj = mysql_fetch_object( $result ) ) {
  $display = ( $session || in_array( $obj->sub_office, $officers ) ? TRUE : FALSE;
  $homephone = ( $display && $obj->homephone ) ? $obj->homephone : '&nbsp';
  $cellphone = ( $display && $obj->cellphone ) ? $obj->cellphone : '&nbsp';
  $email = ( $display && $obj->email ) ? $obj->email : '&nbsp';
  $address = ( $display && $obj->address ) ? $obj->address : '&nbsp';
  $city = ( $display && $obj->city ) ? $obj->city : '&nbsp';
  $state = ( $display && $obj->state ) ? $obj->state : '&nbsp';
  $zip = ( $display && $obj->zip ) ? $obj->zip : '&nbsp';
  $sub_name = ( $display && $obj->sub_name ) ? $obj->sub_name : '&nbsp';
  $html .= <<<ENDHTML
    <tr>
      <td>$obj->sub_office</td>
      <td>$obj->fname $obj->lname</td>
      <td>$homephone / $cellphone</td>
      <td>$email</td>
      <td>$address, $city, $state $zip</td>
      <td>$sub_name</td>
    <\tr>
ENDHTML;
}
Hope this works for you.

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

...

PomonaGrange Aug 13th, 2008 9:32 pm
Re: show club presidents info hide everyone else's
 
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

(SELECT 
  CASE
  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.

langsor Aug 13th, 2008 9:48 pm
Re: show club presidents info hide everyone else's
 
Quote:

Originally Posted by PomonaGrange (Post 669417)
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 :-)

PomonaGrange Aug 13th, 2008 9:54 pm
Re: show club presidents info hide everyone else's
 
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!

langsor Aug 13th, 2008 10:18 pm
Re: show club presidents info hide everyone else's
 
I knew I was pretty tired when I wrote that stuff...glad you found the source of the problem.

Take care


All times are GMT -4. The time now is 2:13 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC