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.
How do I hide a resultset column from being displayed?
Moderator: General Moderators
-
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?
I'm a little puzzled as the answer, assuming I understand your question correctly, is rather simple, i.e., something like:
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
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 " ' '; ?></td> <!--A little extra here-->
</tr>
<?php
} // while
?>
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
Re: How do I hide a resultset column from being displayed?
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.
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.