kbllau Posted April 30, 2009 Share Posted April 30, 2009 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 More sharing options...
the182guy Posted April 30, 2009 Share Posted April 30, 2009 Unless you are trying to target the string literal "NULL" don't enclose it in quotes. Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822576 Share on other sites More sharing options...
revraz Posted April 30, 2009 Share Posted April 30, 2009 And also know, that a Blank data field is not considered NULL. Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822600 Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 echo $row_Recordset12['tel_stu']; if (empty($row_Recordset12["tel_stu"])) { $row["tel_stu"]='style="background:Red"'; }else{ $row["tel_stu"]='style="background:Green"'; } Yes? also, I have no idea what $row is. Not enough information really. Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822603 Share on other sites More sharing options...
revraz Posted April 30, 2009 Share Posted April 30, 2009 Depends if he uses NULL or not. NULL is not empty. Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822616 Share on other sites More sharing options...
kbllau Posted April 30, 2009 Author Share Posted April 30, 2009 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 Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822629 Share on other sites More sharing options...
kbllau Posted April 30, 2009 Author Share Posted April 30, 2009 Yes I mean when the field is empty it should change to red color Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822631 Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 WEll i update my code and what i got that the word ( style="background:red") printed inside the filed instant the filed color change. I have no idea what you just said. ??? Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822632 Share on other sites More sharing options...
kbllau Posted April 30, 2009 Author Share Posted April 30, 2009 Sorry for confusing you: What i meant is instant the cell background change to red color when the is empty. it is now just printing that line inside the field. Thanks Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822659 Share on other sites More sharing options...
BobcatM Posted April 30, 2009 Share Posted April 30, 2009 What about something like this? style.backgroundColor = 'red' Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822694 Share on other sites More sharing options...
jcombs_31 Posted April 30, 2009 Share Posted April 30, 2009 You may have to fill the cell with nonbreaking space. Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822699 Share on other sites More sharing options...
Ken2k7 Posted April 30, 2009 Share Posted April 30, 2009 Can we see more of the code? Or at least the part where you tried to implement the styling. Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822707 Share on other sites More sharing options...
nadeemshafi9 Posted April 30, 2009 Share Posted April 30, 2009 simple php seems so old now i use zend and extjs Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822708 Share on other sites More sharing options...
kbllau Posted April 30, 2009 Author Share Posted April 30, 2009 What about something like this? style.backgroundColor = 'red' no Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822751 Share on other sites More sharing options...
nadeemshafi9 Posted April 30, 2009 Share Posted April 30, 2009 when the cell shows on the screen get a red marker and colour it in Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822754 Share on other sites More sharing options...
kbllau Posted April 30, 2009 Author Share Posted April 30, 2009 nadeemshafi9 Realy Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822765 Share on other sites More sharing options...
nadeemshafi9 Posted April 30, 2009 Share Posted April 30, 2009 nadeemshafi9 Realy trust me i tried it tested it with a test harness and then boundry tested it too Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822769 Share on other sites More sharing options...
kbllau Posted April 30, 2009 Author Share Posted April 30, 2009 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] Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-822780 Share on other sites More sharing options...
nadeemshafi9 Posted May 1, 2009 Share Posted May 1, 2009 <td width="520"><div align="justify" <?php if($row_Recordset12['n_o'] == "") echo "style=\"background-color: red\""?>><?php echo $row_Recordset12['n_o']; ?></div></td> Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-823325 Share on other sites More sharing options...
Sting3r Posted May 1, 2009 Share Posted May 1, 2009 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> Link to comment https://forums.phpfreaks.com/topic/156255-help-to-make-this-work-please/#findComment-823348 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.