Jump to content

Help to make this work please


kbllau

Recommended Posts

Hi

Iam trying to change th cell background color based on the field value so. if it is NULL the background should be RED other wise GREEN  here is te code

<?php
echo $row_Recordset12['tel_stu']; 
      if ($row_Recordset12["tel_stu"]=="NULL") 
{
   $row["tel_stu"]='style="background:Red"';
}else{
  $row["tel_stu"]='style="background:Green"';
}

?>

Any help please

Link to comment
https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/
Share on other sites

WEll i update my code and what i got that the word ( style="background:red") printed inside the filed instant the filed color change.

here is the code:

     if (empty($row_Recordset12['tel_stu'])) 
{
   $row_Recordset12["tel_stu"]='style="background: red"';
}else{
  $row_Recordset12['tel_stu']='style="background: green"';
}

Any help please

here i have attached a photo.

this is my code:

<?php require_once('../Connections/ty.php'); ?>
<?php
$maxRows_Recordset12 = 1;
$pageNum_Recordset12 = 0;
if (isset($_GET['pageNum_Recordset12'])) {
  $pageNum_Recordset12 = $_GET['pageNum_Recordset12'];
}
$startRow_Recordset12 = $pageNum_Recordset12 * $maxRows_Recordset12;

mysql_select_db($database_ty, $ty);
$query_Recordset12 = "SELECT * FROM master ORDER BY master.no_stu";
$query_limit_Recordset12 = sprintf("%s LIMIT %d, %d", $query_Recordset12, $startRow_Recordset12, $maxRows_Recordset12);
$Recordset12 = mysql_query($query_limit_Recordset12, $ty) or die(mysql_error());
$row_Recordset12 = mysql_fetch_assoc($Recordset12);

if (isset($_GET['totalRows_Recordset12'])) {
  $totalRows_Recordset12 = $_GET['totalRows_Recordset12'];
} else {
  $all_Recordset12 = mysql_query($query_Recordset12);
  $totalRows_Recordset12 = mysql_num_rows($all_Recordset12);
}
     if (empty($row_Recordset12['tel_stu'])) 
{
   $row_Recordset12['tel_stu']='style.backgroundColor = red';
}else{
  $row_Recordset12['tel_stu']='style="background: green"';
}
$totalPages_Recordset12 = ceil($totalRows_Recordset12/$maxRows_Recordset12)-1;
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<title>Untitled Document</title>
</head>

<body>
<table border="1">
  <tr align="center">
    <td colspan="2"><div align="justify">fileno <?php echo $row_Recordset12['no_stu']; ?></div></td>
  </tr>
  <?php do { ?>
    <tr align="center">
      <td width="520"><div align="justify"><?php echo $row_Recordset12['n_o']; ?></div></td>
      <td width="160"><div align="right">serial</div></td>
    </tr>
    <tr align="center">
      <td><div align="justify"><?php echo $row_Recordset12['no_stu']; ?></div></td>
      <td><div align="right">file </div></td>
    </tr>
    <tr align="center">
      <td><div align="justify"><?php echo $row_Recordset12['first_nm']; ?> <?php echo $row_Recordset12['last_nm']; ?></div></td>
      <td><div align="right">name</div></td>
    </tr>
    <tr align="center">
      <td><div align="justify"><?php echo $row_Recordset12['date_birth']; ?></div></td>
      <td><div align="right">dob </div></td>
    </tr>
    <tr align="center">
      <td><div align="justify"><?php echo $row_Recordset12['add_stu']; ?><br />
        <?php echo $row_Recordset12['postcode']; ?></div></td>
      <td><div align="right">address </div></td>
    </tr>
    <tr align="center">
      <td><div align="justify"><?php
  echo $row_Recordset12['tel_stu']; ?></div></td>
      <td><div align="right">tel</div></td>
    </tr>
    <tr align="center">
      <td><div align="justify"><?php echo $row_Recordset12['mb_stu']; ?></div></td>
      <td><div align="right">mobile</div></td>
    </tr>
    <tr align="center">
      <td><div align="justify"><?php echo $row_Recordset12['first_date']; ?></div></td>
      <td><div align="right">dof </div></td>
    </tr>
    <tr align="center">
      <td><div align="justify"><?php echo $row_Recordset12['last_date']; ?></div></td>
      <td><div align="right">dos</div></td>
    </tr>
    <tr align="center">
      <td><div align="justify"><?php echo $row_Recordset12['no_grad']; ?></div></td>
      <td><div align="right">grade</div></td>
    </tr>
    <tr align="center">
      <td><div align="justify"><?php echo $row_Recordset12['no_unv']; ?></div></td>
      <td><div align="right">university</div></td>
    </tr>
    <tr align="center">
      <td><?php echo $row_Recordset12['no_dep']; ?></td>
      <td><div align="right">section</div></td>
    </tr>
    <?php } while ($row_Recordset12 = mysql_fetch_assoc($Recordset12)); ?>
</table>
<div align="center"></div>
<div align="center"></div>
</body>
</html>
<?php
mysql_free_result($Recordset12);
?>

 

[attachment deleted by admin]

thats cause your php code should be in the div tags. You have them placed outside.

 

replace :

<td><div align="justify"><?php
     echo $row_Recordset12['tel_stu']; ?></div></td>

 

with

 

<td><div align="justify" <?php
     echo $row_Recordset12['tel_stu']; ?>></div></td>

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.