ndanet Posted September 19, 2009 Share Posted September 19, 2009 I have a personal website that I am working on that is design using php & Mysql. One of the pages is made up of three tables. The first table on the left consist of a bunch of equal rows and columns for instance lets say 6 rows x 6 columns totally 36 individual cells. Each one of those cells consist on information stored in a mysql database. Each cells contains four lines of content, first line is cells number (always the same 1, 2, 3, so on) second line is user firstname, third line is user lastname, and fourth line is active = (yes or no). Located on the right side of this page is another totally separate table that pulls all the active usernames and list in rows. This username is not the mysql fields named firstname, and lastname. It is a totally separate field, which cannot be changed. Also, just so you know I don't think it matters, but both tables are individual and are each php include files. I am trying to highlight the cells on the right when scrolling over the username on the left associated with that user. Someone supplied me with some javascript that i think would work fine if I can figure out how to include this properly in my code. Here is a copy of the javascript: -------------------------------------------------------- <script type="text/javascript"> /*<![CDATA[*/ function HighLight(cls,txt){ var cells=zxcByClassName(cls) for (var td,z0=0;z0<cells.length;z0++){ td=cells[z0]; while (td.parentNode&&td.nodeName.toUpperCase()!='TD'){ td=td.parentNode; } if (td.nodeName.toUpperCase()=='TD'){ td.style.backgroundColor=cells[z0].innerHTML!=txt?'red':'blue'; } } } function zxcByClassName(nme,el,tag){ if (typeof(el)=='string') el=document.getElementById(el); el=el||document; for (var tag=tag||'*',reg=new RegExp('\\b'+nme+'\\b'),els=el.getElementsByTagName(tag),ary=[],z0=0; z0<els.length;z0++){ if(reg.test(els[z0].className)) ary.push(els[z0]); } return ary; } /*]]>*/ </script> -------------------------------------------------------- Visit the following website to see what I am trying to do: http://www.ndanet.com/roll.php Here is a piece of my code displaying the content in the table on the right side of the screen prior to the javascript: -------------------------------------------------------- <td width="70" height="50"><div align="center"> <?php $count = 0; $db = mysql_pconnect("", "", ""); mysql_select_db("",$db); $result1 = mysql_query("SELECT * FROM 36_cells where id=2",$db); $myrow1 = mysql_fetch_array($result1); printf ("<font face=\"arial\" size=\"1\" color=\"cccccc\">cell #%s<br></font>",$myrow1["id"]); printf ("<font face=\"verdana\" size=\"1\" color=\"666666\">%s<br></font>",$myrow1["firstname"]); printf ("<font face=\"verdana\" size=\"1\" color=\"666666\">%s<br></font>",$myrow1["lastname"]); if ( $myrow1["status"] == "NULL" ) { echo ('<a href="activate.php?id=2"><font face="Arial, Helvetica, sans-serif" size="2" color=FF0000>ACTIVATE</font></a>'); } elseif ( $myrow1["status"] == "yes" ){ echo ('<font face="Georgia, Times New Roman, Times, serif" size="2" color=FF0000>ACTIVE</font>'); } else { echo "NOT ACTIVE"; } ?> </div></td> -------------------------------------------------------- I know I need to include <span class="name"></span> in the area of code, but where? I tried it in a couple of places and still cannot get the code to work. Now here is a piece of code located from the table on the right displaying active users: (before javascript code) -------------------------------------------------------- <?php $count = 0; $db = mysql_pconnect("", "", ""); mysql_select_db("",$db); $result2 = mysql_query ("SELECT DISTINCT usernames FROM 36_cells"); if ($myrow2 = mysql_fetch_array($result2)) { do { if ($count == 0) { print ("<body bgcolor=\"#FFFFFF\" text=\"#000000\"><div align=\"center\"><table width=\"300\" border=\"0\" bgcolor =\"E9E9E9\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#FFFFFF\"> <tr>"); printf ("<td width = \"300\"><font face=\"verdana\" size=\"1\" color=\"666666\">%s</font></td>",$myrow2["usernames"]); print ("</tr> </table> </div>"); $count = 1; } else { print ("<body bgcolor=\"#FFFFFF\" text=\"#000000\"><div align=\"center\"><table width=\"300\" border=\"0\" bgcolor =\"E9E9E9\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#FFFFFF\"> <tr>"); printf ("<td width = \"300\"><font face=\"verdana\" size=\"1\" color=\"666666\">%s</font></td>",$myrow2["usernames"]); print ("</tr> </table> </div>"); $count = 0; }}while ($myrow2 = mysql_fetch_array($result2)); }?> -------------------------------------------------------- (after me trying to get it to work with javascript) <?php $count = 0; $db = mysql_pconnect("", "", ""); mysql_select_db("",$db); $result2 = mysql_query ("SELECT DISTINCT usernames FROM 36_cells"); if ($myrow2 = mysql_fetch_array($result2)) { do { if ($count == 0) { print ("<body bgcolor=\"#FFFFFF\" text=\"#000000\"><div align=\"left\"><table width=\"300\" border=\"0\" onMouseOut=\"HighLight('name','???');\" bgcolor =\"E9E9E9\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#FFFFFF\"><tr>"); printf ("<td width = \"300\"><span=\"mse\" onMouseOver=\"HighLight('name','",$myrow2["usernames"],"')\"><font face=\"verdana\" size=\"1\" color=\"666666\"></span>%s</font></td>",$myrow2["usernames"],""); print ("</tr> </table> </div>"); $count = 1; } else { print ("<body bgcolor=\"#FFFFFF\" text=\"#000000\"><div align=\"left\"><table width=\"300\" border=\"0\" bgcolor =\"FFFFFF\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#FFFFFF\"> <tr>"); printf ("<td width = \"300\"><span=\"mse\" onMouseOver=\"HighLight('name','",$myrow2["usernames"],"')\"><font face=\"verdana\" size=\"1\" color=\"666666\"></span>%s</font></td>",$myrow2["usernames"],""); print ("</tr> </table> </div>"); $count = 0; }}while ($myrow2 = mysql_fetch_array($result2)); }?> -------------------------------------------------------- If anyone can help me out, I would GREATLY appreciate it. Also if there is an easier way please let me know. Quote Link to comment 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.