Ghosty Posted March 31, 2010 Share Posted March 31, 2010 Basically, If the message is unread (read=0) I want the message to be yellow, otherwise I want it to be transparent, looked around at codes on the internet and on this site but can't see anything that would help me Here is all the code: <?php session_start(); include_once "includes/db_connect.php"; include_once "includes/functions.php"; logincheck(); $username=$_SESSION['username']; $query=mysql_query("SELECT * FROM `inbox` WHERE `to`='$username'"); $fetch=mysql_fetch_object($query); $biatch=mysql_query("SELECT * FROM `inbox` WHERE `to`='$username'"); $fucktard = mysql_fetch_object($biatch); $query=mysql_query("SELECT * FROM users WHERE username='$username'"); $fetch22=mysql_fetch_object($query); if ($_GET['del']){ $del=$_GET['del']; $checker = mysql_query("SELECT * FROM `inbox` WHERE `to` ='$username' AND `id` ='$del' "); $rows=mysql_num_rows($checker); if ($rows > "0"){ echo "Message Deleted"; mysql_query("DELETE FROM inbox WHERE id='$del'"); }}////END DELETE THERE MSG if (strip_tags($_POST['Dall'])){ mysql_query("DELETE FROM `inbox` WHERE `saved`='0'"); echo "<font color=orange><b><center>Mailbox Cleaned</font></b>"; } if (strip_tags($_POST['D_s'])){ if(is_array($_POST['radio'])) { foreach($_POST['radio'] as $value) { mysql_query("DELETE FROM inbox WHERE id='$value'"); } echo "<font color=orange><b><center>Messages Successfully Deleted</font></b>"; }} if ($_GET['s']){ $save=$_GET['s']; mysql_query("UPDATE inbox SET saved='1' WHERE id='$save'"); print "Message Saved"; } echo "<center>"; $mysql1 = mysql_query("SELECT * FROM `inbox` WHERE `to`='$username' AND `saved` ='0' ORDER by date DESC"); $num_rows =mysql_num_rows($mysql1); while($get = mysql_fetch_object($mysql1)){ $t++; $n++; } $true=mysql_fetch_object(mysql_query("SELECT * FROM networks WHERE id='$shit->networ_kinvite'")); $numba = mysql_num_rows(mysql_query("SELECT * FROM users WHERE network='$true->network'")); if (strip_tags($_GET['join_network'])){ mysql_query("UPDATE users SET network='$true->name', network_invite='0' WHERE username='$username'"); echo "<font color=orange><b><center>You are now in that Crew</font></b>"; } if (($_POST['change_ringtone']) && strip_tags($_POST['profilring'])){ $profilring=mysql_real_escape_string(strip_tags($_POST['profilring'])); mysql_query("UPDATE users SET rintone='$profilring' WHERE username='$username'"); echo "<font color=orange><center><b>Your ringtone has been updated.</font></b>"; } ?> <link href="includes/in.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- body { background-image: url(images/pattern.png); background-repeat: repeat; } --> </style><head> <script language="javascript"> function toggle(a) { var e = document.getElementById(a); if(!e) return true; if(e.style.display == "none") { e.style.display = "block" } else { e.style.display = "none" } return true; } function getItem(id) { var itm = false; if(document.getElementById) itm = document.getElementById(id); else if(document.all) itm = document.all[id]; else if(document.layers) itm = document.layers[id]; return itm; } function toggleItem(id) { itm = getItem(id); if(!itm) return false; if(itm.style.display == 'none') itm.style.display = ''; else itm.style.display = 'none'; return false; } </script> <style type="text/css"> table.collapseColumns td { visibility: hidden; } </style> <script type="text/javascript"> <!-- function setupTables() { var tables = document.getElementsByTagName('table'); for (var tableLoop=0; tableLoop<tables.length; tableLoop++) { if (tables[tableLoop].className == 'collapseColumns') { var headerRow = tables[tableLoop].tHead.rows[0].cells; for (var cellLoop=0; cellLoop<headerRow.length; cellLoop++) { headerRow[cellLoop].onclick = toggleColumn; headerRow[cellLoop].style.cursor = 'pointer'; } } } } function toggleColumn() { var table = this.parentNode.parentNode.parentNode; var columnNumber = this.cellIndex; var isShowing = (table.tBodies[0].rows[0].cells[columnNumber].style.visibility == 'visible'); var rows = table.tBodies[0].rows; for (var rowLoop=0; rowLoop<rows.length; rowLoop++) { rows[rowLoop].cells[columnNumber].style.visibility = isShowing ? 'hidden' : 'visible'; } } //--> </script> <script type="text/javascript"> function poorman_toggle(id) { var tr = document.getElementById(id); if (tr==null) { return; } var bExpand = tr.style.display == ''; tr.style.display = (bExpand ? 'none' : ''); } function poorman_changeimage(id, sMinus, sPlus) { var img = document.getElementById(id); if (img!=null) { var bExpand = img.src.indexOf(sPlus) >= 0; if (!bExpand) img.src = sPlus; else img.src = sMinus; } } function Toggle_trGrpHeader2() { poorman_changeimage('trGrpHeader2_Img', 'images/minus.gif', 'images/plus.gif'); poorman_toggle('row1'); poorman_toggle('row2'); poorman_toggle('row3'); } function Toggle_trGrpHeader1() { poorman_changeimage('trGrpHeader1_Img', 'images/minus.gif', 'images/plus.gif'); poorman_toggle('trRow1'); } </script> <script language=javascript> checked=false; function checkedAll (frm1) { var aa= document.getElementById('frm1'); if (checked == false) { checked = true } else { checked = false } for (var i =0; i < aa.elements.length; i++) { aa.elements.checked = checked; } } </script> <form action='' method=POST name=f id ='frm1'> <p align="center"> <input name='Dall' type='submit' id='Dall' value='Empty Inbox' /> <br> </p> <div align="center"> <div align="center"> <input name='D_s' type='submit' id='Delete_s' value='Delete Selected' /> <table width="568" border="0" cellpadding="0" cellspacing="5"> <tr> <td> </td> </tr> </table> <div align="center"> </div> <div align="center"> </div> <div align="center"> <table width="560" border="1" cellpadding="2" cellspacing="0" class="TextBox"> <tr > <td width="552" height="29" background="images/GWGrad.png" class="TMNBlackFont"><center><font color="#FFFFFF">Messages</font></center></td> </tr> </table> <br /> <table width="560" border="1" cellpadding="2" cellspacing="0" class=GridRow id="myTbody[1]"> <!--DWLayoutTable--> <tr class="GridHeader" background="images/GWGrad.png"> <td width="37" class=GridHeader><input type='checkbox' name='checkall' onclick='checkedAll(frm1);' /></td> <td width="135" class=GridHeader> <font color="#FFFFFF">From</font></td> <td width="540" class=GridHeader><font color="#FFFFFF">Subject</font></td> </tr> <? $c=mysql_query("SELECT * FROM `inbox` WHERE `to`='$username' ORDER by date DESC"); while($d=mysql_fetch_object($c)){ echo "<tr class='GridRow'> <td><input type=\"checkbox\" name=\"radio[]\" value=\"$d->id\"></td><td><a href='Profile.php?viewuser=$d->from'>$d->from</a></td><td><a href='ViewMessage.php?viewmessage=$d->id'>$d->subject</a></td></tr></form>"; } ?> </table> </div> <p align="center"> <script language=javascript> checked=false; function selectedAll (frm2) { var aa= document.getElementById('frm2'); if (checked == false) { checked = true } else { checked = false } for (var i =0; i < aa.elements.length; i++) { aa.elements.checked = checked; } } </script> </p> <div align="center"> <? include_once "inbox.php"; ?> </form> <head> </p> Quote Link to comment https://forums.phpfreaks.com/topic/197116-changing-color-depending-on-a-value/ Share on other sites More sharing options...
Jax2 Posted March 31, 2010 Share Posted March 31, 2010 Not quite sure where in your code you want to change the font color ... on the off chance it will work, couldn't you just use an if/else statement? I.e. if ($row['read']=="0") { echo "<font color=yellow>".$row['messagetitle']."</font>"; }//end if ELSE { echo $row['messagetitle']; }//end ELSE Quote Link to comment https://forums.phpfreaks.com/topic/197116-changing-color-depending-on-a-value/#findComment-1034745 Share on other sites More sharing options...
Ghosty Posted March 31, 2010 Author Share Posted March 31, 2010 I want it to show the message subject in a different color if the message is read/unread. I entered that code and it comes up with this on the page: if ($row['read']=="0") { echo "".$row['subject'].""; }//end if ELSE { echo $row['subject']; }//end ELSE Quote Link to comment https://forums.phpfreaks.com/topic/197116-changing-color-depending-on-a-value/#findComment-1034754 Share on other sites More sharing options...
Jax2 Posted March 31, 2010 Share Posted March 31, 2010 Is this the part of the code you're talking about? If it shows that, that generally means that wherever you're putting the code, it hasn't been defined as being PHP, in other words, you've escaped PHP ... <? $c=mysql_query("SELECT * FROM `inbox` WHERE `to`='$username' ORDER by date DESC"); while($d=mysql_fetch_object($c)){ echo "<tr class='GridRow'> <td><input type=\"checkbox\" name=\"radio[]\" value=\"$d->id\"></td><td><a href='Profile.php?viewuser=$d->from'>$d->from</a></td><td><a href='ViewMessage.php?viewmessage=$d->id'>$d->subject</a></td></tr></form>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/197116-changing-color-depending-on-a-value/#findComment-1034767 Share on other sites More sharing options...
Ghosty Posted March 31, 2010 Author Share Posted March 31, 2010 Yeh that is the part of the code. Quote Link to comment https://forums.phpfreaks.com/topic/197116-changing-color-depending-on-a-value/#findComment-1034768 Share on other sites More sharing options...
Jax2 Posted March 31, 2010 Share Posted March 31, 2010 <?php $c=mysql_query("SELECT * FROM `inbox` WHERE `to`='$username' ORDER by date DESC"); while($d=mysql_fetch_object($c)){ echo "<tr class='GridRow'>"; echo "<td><input type=\"checkbox\" name=\"radio[]\" value=\"$d->id\"></td>"; echo "<td><a href='Profile.php?viewuser=$d->from'>$d->from</a></td>"; if ($d->read=="0") { echo "<td><font color='yellow'><a href='ViewMessage.php?viewmessage=$d->id'>$d->subject</a></font></td>"; } //end IF ELSE { echo "<td><a href='ViewMessage.php?viewmessage=$d->id'>$d->subject</a></td>"; } //end ELSE echo "</tr></form>"; } //end WHILE ?> Something like that should work. In other words, if read=0, set it to yellow, if not, leave it the normal color. If you want to change the color for ones where read=1, you could set that in the second statement after the ELSE Quote Link to comment https://forums.phpfreaks.com/topic/197116-changing-color-depending-on-a-value/#findComment-1034775 Share on other sites More sharing options...
Ghosty Posted March 31, 2010 Author Share Posted March 31, 2010 Thank for your help Jax2, all that seems to do is add a new row with 3 columns: id\"> $d->from $d->subject Quote Link to comment https://forums.phpfreaks.com/topic/197116-changing-color-depending-on-a-value/#findComment-1034803 Share on other sites More sharing options...
Jax2 Posted March 31, 2010 Share Posted March 31, 2010 Ahh, hold on a sec lol .... <?php $sql="SELECT * FROM inbox WHERE to=$username ORDER by date DESC"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { echo "<tr class='GridRow'>"; echo "<td><input type='checkbox' name='radio[]' value='".$row['id']."'></td>"; echo "<td><a href='Profile.php?viewuser=".$row['from']."'>".$row['from']."</a></td>"; if ($row['read']=="0") { echo "<td><font color='yellow'><a href='ViewMessage.php?viewmessage=".$row['id'].">".$row['subject']."</a></font></td>"; } //end IF ELSE { echo "<td><a href='ViewMessage.php?viewmessage=".$row['id']."'>".$row['subject']."</a></td>"; } //end ELSE echo "</tr></form>"; } //end WHILE ?> That should work just fine. Quote Link to comment https://forums.phpfreaks.com/topic/197116-changing-color-depending-on-a-value/#findComment-1034815 Share on other sites More sharing options...
Ghosty Posted March 31, 2010 Author Share Posted March 31, 2010 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mafiawor/public_html/inbox.php on line 248 line 248: while($row=mysql_fetch_array($result)) Brings up that error Quote Link to comment https://forums.phpfreaks.com/topic/197116-changing-color-depending-on-a-value/#findComment-1034828 Share on other sites More sharing options...
jcbones Posted March 31, 2010 Share Posted March 31, 2010 That error means your query failed. Quote Link to comment https://forums.phpfreaks.com/topic/197116-changing-color-depending-on-a-value/#findComment-1034944 Share on other sites More sharing options...
ialsoagree Posted March 31, 2010 Share Posted March 31, 2010 If $username is a string, it needs to be escaped... $sql="SELECT * FROM inbox WHERE to='$username' ORDER by date DESC"; Quote Link to comment https://forums.phpfreaks.com/topic/197116-changing-color-depending-on-a-value/#findComment-1034961 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.