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
https://forums.phpfreaks.com/topic/77068-solved-hide-row-if-column-empty/
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
}

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...

 

 

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>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.