How do I hide a resultset column from being displayed?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomex1
Forum Commoner
Posts: 26
Joined: Sun Aug 16, 2009 11:34 am

How do I hide a resultset column from being displayed?

Post by tomex1 »

Hello,
I am running a query like SELECT a, b,c FROM table from my php page. a is a status column in the database with values 'Y' or 'N'. I don't want this column to be displayed to the user but I need this column to pass a visual message to the user depending on the value of row 'a'. Please how do I go about doing this considering the fact that if I don't select 'a' as part of my query then I won't be a able to do what I intend doing?

Cheers.
PeteClimbs
Forum Newbie
Posts: 2
Joined: Sun Aug 23, 2009 9:33 am
Location: Saranac Lake, New York

Re: How do I hide a resultset column from being displayed?

Post by PeteClimbs »

I'm a little puzzled as the answer, assuming I understand your question correctly, is rather simple, i.e., something like:

Code: Select all

 
<?php
$key=$_GET['key']; // or whatever
$dbconn=new mysqli('host','usreid','passwd','db_name') or die(' Connect Error!');
$result=$dbconn->query("SELECT a,b,c FROM locks WHERE the_key='$key') or die('Foo!');
// Ok, here we go and display the resulting data as rows in a table.
?>
<table border="1" cellspacing="0">
  <tr>
    <th>B</th>
    <th>C</th>
  </tr>
<?php 
  while ($obj=$result->fetch_object()) {
    if ($obj->a=='Y') {
?>  <tr>
        <td><?php echo $obj->b; ?></td>
        <td><?php echo $obj->c ? $obj->c " '&nbsp;'; ?></td> <!--A little extra here-->
      </tr>
<?php 
  } // while 
?>
 
Note that the column 'a' is not dsplayed on the web page.

Warning: I didn't test this code and often make typos so it may not run as-is, but it should convey the idea.

Hope this helps

Pete
tomex1
Forum Commoner
Posts: 26
Joined: Sun Aug 16, 2009 11:34 am

Re: How do I hide a resultset column from being displayed?

Post by tomex1 »

Hi PeteClimbs,
Thanks a lot! The question seems so easy bcos I didn't paste what I already had which I should have done. I actually had something similar to what your answer and I was just curious if there's another way of achieving this.

Thanks.
Post Reply