Log in

View Full Version : Incorporate javascipt to work with my php & mysql



jeremyb
09-14-2009, 08:53 PM
could anyone help me out with an issue I am having incorporating java script to work a website I am trying to create. The concept of this page is that I have a table created with 100 cells in it. Each cell is assigned to an entry already created in a mysql database. On the right side of that table I have another table with a list of distinct members assigned to the cells on the left. What I am trying to do is when you scroll over the members name on the right it will highlight the cells in the table on the left associated with that member.

I have someone who provided me with a java scipt that functions like I wish however I am having problem incorporating it into the php code. One of the things I noticed is that when I pull the distinct members the field is called "responsible member" but with is posted in the cells on the left is two fields called "firstname" and "lastname". The reason I did it this way is because sometime the first name and last name may change but that responsible member will remain the same. Here is a small piece of the code I am working with. Any suggestions will greatly be appreciated.

---

Now on the right I pull distinct members located in the same database however in a cell called "responsible_member". Here is a piece of code to see what I am talking about.

Also, I want you to know that I used php include files to pull all this information into the index.
----------

index.php (located on the left side - this is only a small piece of the code)

<?php
$count = 0;
$db = mysql_pconnect("", "", "");
mysql_select_db("",$db);
$result1 = mysql_query("SELECT * FROM 100_cells where id=1",$db);
$myrow1 = mysql_fetch_array($result1);
printf ("<font face=\"arial\" size=\"1\" color=\"cccccc\">square #%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="complete_100_cells_1.php?id=1"><font face="Arial, Helvetica, sans-serif" size="2" color=FF0000>FILL IN</font></a>');
} elseif ( $myrow1["status"] == "yes" ){
echo ('<font face="Georgia, Times New Roman, Times, serif" size="2" color=FF0000>YES</font>');
} else {
echo "AVAILABLE";
}
?>


-----------

members.php (located on the right side - this is only a small piece of the code)

<?php
$count = 0;
$db = mysql_pconnect("", "", "");
mysql_select_db("",$db);
$result2 = mysql_query ("SELECT DISTINCT responsible_member FROM 100_cells WHERE responsible_member NOT LIKE 'Admin' ORDER BY timesent");
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["responsible_member"]);
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["responsible_member"]);
print ("</tr>
</table>
</div>");
$count = 0;
}}while ($myrow2 = mysql_fetch_array($result2));
}?>

--------
mysql database

id (1 - 100)
timesent (time stamp when data entered)
firstname (determined by member)
lastname (determined by member)
status
responsible_members (consist of firstname and lastname from another database - hardly ever the same as firstname and lastname of this database)

---------

jeremyb
09-14-2009, 09:03 PM
Sorry,

this is the java script working on another page but, this is the concept of what I am trying to do.

http://www.ndanet.com/roll.php

here is a copy of the java scipt on that page: roll.php
------------

<!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" xml:lang="en" lang="en">

<head>
<title></title>
<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>

</head>

<body>
<table border="1">
<tr>
<td><span class="name" >Name 1</span></td>
<td><span class="name" >Name 2</span></td>
<td><span class="name" >Name 3</span></td>
<td><span class="name" >Name 4</span></td>
</tr>
<tr>
<td><span class="name" >Name 1</span></td>
<td><span class="name" >Name 2</span></td>
<td><span class="name" >Name 3</span></td>
<td><span class="name" >Name 4</span></td>
</tr>
<tr>
<td><span class="name" >Name 1</span></td>
<td><span class="name" >Name 2</span></td>
<td><span class="name" >Name 3</span></td>
<td><span class="name" >Name 4</span></td>
</tr>
<tr>
<td><span class="name" >Name 1</span></td>
<td><span class="name" >Name 2</span></td>
<td><span class="name" >Name 3</span></td>
<td><span class="name" >Name 4</span></td>
</tr>
</table>
<table border="1" onmouseout="HighLight('name','???');">
<tr>
<td class="mse" onmouseover="HighLight('name','Name 1');" >Name 1</td>
</tr>
<tr>
<td class="mse" onmouseover="HighLight('name','Name 2');" >Name 2</td>
</tr>
<tr>
<td class="mse" onmouseover="HighLight('name','Name 3');" >Name 2</td>
</tr>
<tr>
<td class="mse" onmouseover="HighLight('name','Name 4');" >Name 4</td>
</tr>
</table>

</body>

</html>