Trying to incorporate javascript into php

Hi. I’ve been working on an events calendar and now I’m at a point where I’m trying to call javascript functions within php. The javascript creates a tooltip on mouseovers, but eventually I will want to fill those tool tips with information called by php from a mysql database. Problem is that I can’t figure out how to recognize the javascript functions without hurting the php code that I have.

here is the php that I have

<?php
echo "<tr>";
	
	for($i = 1; $i < $numDays+1; $i++, $counter++){
		   
/////and so on.......

	echo ">";
	echo"<a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$daystring."&year=".$year."&f=true'>" . $i . " </a></td>";	
	}
?>

and I’m trying to encase the link (for now it’s a link, but eventually will totally be replaced with this javascript function) with this:

[

<span class="hotspot" onmouseover="tooltip.show('

and this will eventually show information shown from a database

');" onmouseout="tooltip.hide();">


//link here//

</span>

I’m sure this is probably some kind of simple escape, but no matter how I’ve traded quotation marks or slashes I’ve not been able to get this. I even tried completely escaping the php briefly before and after the link but it didn’t work either.
Thanks.

I’m almost where I need to be now, but this is now where I’m having a problem.

I’ve set up a string of variable to be displayed within the $tooltip variable here:


$sqlEvent = "SELECT * FROM eventscalendar where eventDate='".$monthstring."/".$daystring."/".$year."'";
			$resultEvents = mysql_query($sqlEvent);
			$events = mysql_fetch_array($resultEvents);
	
			$tooltip = "<div><b>".$events['holiday']." <br/>".$events['eventDate']."<br/>".$events['heading']."<br/>".$events['event1']."<br/>".$events['event2']."<br/>".$events['event3']."<br/>".$events['event4']."</b></div>";
						
			echo "><span onmouseover='tooltip.show(\\"$tooltip\\");' onmouseout='tooltip.hide();'>\
". $i ."</span></td>\
";

But I’m wondering if it’s possible to place a class or id on the html that I have within the variable. I tried and it displayed my calendar all crazy, I even tried escaping it with forward slashes. Do I need to escape to call this class, or is this just not even possible?

This is what I tried:



			$tooltip = "<div class='tips'
><b>".$events['holiday']." <br/>".$events['eventDate']."<br/>".$events['heading']."<br/>".$events['event1']."<br/>".$events['event2']."<br/>".$events['event3']."<br/>".$events['event4']."</b></div>";
						

Okay I figured out pretty much all of those problems. Now I’m just trying to figure out how to position my tooltip and we’ll see how that goes.

Okay, so I tried that and the tooltip works as far as displaying a message on a hover, but now I’m having trouble assigning specific date information to each date. In order to make it work I have to click on a date with an event on it, and then the only information that will come up on the tool tip is the information for that event.

I also for some reason have two different hotspots within each date, one that is the intended number, and the other is a blank dotted red line.

here is what I have so far this area of code.


<?php
echo "<tr>";
	for($i = 1; $i < $numDays+1; $i++, $counter++){
		$timeStamp = strtotime("$year-$month-$i");
		if($i==1){
			$firstDay = date("w", $timeStamp);
				for ($j = 0; $j < $firstDay; $j++, $counter++){
				//blank space
				echo "<td>&nbsp;</td>";
				}
			}
			if($counter &#37; 7 == 0){
				echo "</tr><tr>";
				}
				$monthstring = $month;
				$monthlength = strlen($monthstring);
				$daystring = $i;
				$daylength = strlen($daystring);
				if($monthlength <= 1){
					$monthstring = "0".$monthstring;
				}
				if($daylength <= 1){
					$daystring = "0".$daystring;
				}
				$todaysDate = date("m/d/Y");
				$dateToCompare = $monthstring . '/' . $daystring . '/' . $year;
				echo "<td "; 
				if($todaysDate == $dateToCompare){
					echo "class = 'today'";
					}else{
						$sqlCount = "select * from eventscalendar where eventDate='".$dateToCompare."'";
						$noOfEvent = mysql_num_rows(mysql_query($sqlCount));
						if ($noOfEvent >= 1){
							echo "class = 'event'";
							}else{
								echo "class = 'regday'";
						}	
				}
			$sqlEvent = "SELECT * FROM eventscalendar where eventDate='".$month."/".$day."/".$year."'";
			$resultEvents = mysql_query($sqlEvent);
			$events = mysql_fetch_array($resultEvents);
	
			$tooltip = $events['holiday']." <br/>".$events['eventDate']."<br/>".$events['heading']."<br/>".$events['event1']."<br/>".$events['event2']."<br/>".$events['event3']."<br/>".$events['event4'];
						
			echo "><span class='hotspot' onmouseover='tooltip.show(\\"$tooltip\\");' onmouseout='tooltip.hide();'>\
";
			echo"<a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$daystring."&year=".$year."&f=true'>" . $i . " </a>\
";	
			echo "</span></td>\
";
			}

I know that the link is causing problems, the “f=true” part of the url includes with a click the information that I’m trying to include instead with a hover.

You didn’t provide the JS to test with, but the code this produces is correct:

<?php

/* TEST VARIABLES */
$tooltip = 'and this will eventually show information shown from a database';
$numDays = '2';
$monthstring = '07';
$daystring = '10';
$year = '2010';
$php = $_SERVER['PHP_SELF'];

echo "<tr>";
    
for ($i = 1; $i < $numDays+1; $i++){
    echo "<td><span class='hotspot' onmouseover='tooltip.show(\\"$tooltip\\");' onmouseout='tooltip.hide();'>\
"; 
    echo "<a href='$php?month=$monthstring&day=$daystring&year=$year&f=true'>$i</a>\
";
    echo "</span></td>\
";
}

echo "</tr>";

?>