Jump to content

[SOLVED] hide row if column empty


tylercaiden

Recommended Posts

Hi! I would like to hide the rows where the "points" column is empty. I am ordering by points desc and half the users do not have points.

 

$query  = "select * from user ORDER BY `Points` DESC";
$result = mysql_query($query);

while($row = mysql_fetch_assoc($result))
{

$Html_Listp = $Html_Listp."<table width='84%' border='0' align='center' cellpadding='2' cellspacing='0'>
                <tr>
                  <td width='4%'><input name='CHECKID' type='checkbox' class='title_list1' value='$id'></td>
                  <td width='32%' class='title_list'>{$row['name']}</td>
                  <td width='26%' class='title_list'>{$row['user']}</td>
                  <td width='24%' class='title_list'>{$row['Points']}</td>
                  <td width='14%' class='title_list'>{$row['id']}</td>
                </tr>
              </table>";

Link to comment
Share on other sites

You could say something like:

 

if ($row['Points'] == "") {
   // do something here
} else {
   // do something else here
}

 

>> OR if your using NULL fields in your database <<

 

if ($row['Points'] == NULL) {
   // do something here
} else {
   // do something else here
}

Link to comment
Share on other sites

Also with your code... You do not have to keep your TABLE in PHP... you can go in and out of it as long as it's within php brackets

 

Example:

 

<?php
while($row = mysql_fetch_assoc($result))
{
   $Html_Listp = $Html_Listp
?>
<table width='84%' border='0' align='center' cellpadding='2' cellspacing='0'>
                <tr>
                  <td width='4%'><input name="CHECKID" type='checkbox' class='title_list1' value='<?php echo $id; ?>'></td>
                  <td width='32%' class='title_list'><?php echo $row['name']; ?></td>
                  <td width='26%' class='title_list'><?php echo $row['user']; ?></td>
                  <td width='24%' class='title_list'><?php echo $row['Points']; ?></td>
                  <td width='14%' class='title_list'><?php echo $row['id']; ?></td>
                </tr>
         </table>
<?php 
// end the while loop here.
} 
?>

 

Also if you do it this way I would say to change the single quotes ( ' ) to double quotes ( " )  for html...

 

 

Link to comment
Share on other sites

i think im doing this wrong, sorry im very new to php...

i tried setting it up like this thinking it will print all rows greater than 0 but it only prints one row

 

$query  = "select * from user ORDER BY `Points` DESC";
$result = mysql_query($query);

while($row = mysql_fetch_assoc($result))

if ($row['Points'] > 0) {
$Html_Listp = "<table width='84%' border='0' align='center' cellpadding='2' cellspacing='0'>
                <tr>
                  <td width='4%'><input name='CHECKID' type='checkbox' class='title_list1' value='$id'></td>
                  <td width='32%' class='title_list'>{$row['name']}</td>
                  <td width='26%' class='title_list'>{$row['user']}</td>
                  <td width='24%' class='title_list'>{$row['Points']}</td>
                  <td width='14%' class='title_list'>{$row['id']}</td>
                </tr>
              </table>";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.