Here's something that I tested without the PHP and it worked ok. Now that I've introduced the PHP to the document it doesn't work.
The PHP variable is not passing to Javascript properly. By use of some cleverly placed alert boxes, I figured out that the only thing that is getting passed forward is something called : "object HTML ImageElement"
Specifically, I assign the element ID the unique ID number of the record in the SQL database. The problem isn't with the ID numbers themselves: They are alphanumeric and unique.
I think it boils down to one of two lines of code. Either this isn't working (about line 12)
Code:
function expander(RecordID){
or perhaps it is when I am calling the function (about line 66):
Code:
echo "<img id='".$row['IDNumber']."' src=".$row['ImagePath']." width='5%' onMouseOver='expander(".$row['IDNumber'].");' onMouseOut='shrinker(".$row['IDNumber'].");'>";}
The PHP works (I can get the images to appear, so the connection to SQL and such isn't a problem). I am sure most of the JavaScript is good, too, as I said I had it all working prior to dropping in the PHP.
Since I am not going from JavaScript to PHP I don't think I need AJAX. I just need the PHP to pass to JavaScript.
Any ideas?
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="class.css" />
<script type = "text/javascript" language="javascript">
//<![CDATA[
var maxheight = 150;
var countShrink = 1;
function expander(RecordID){
var countGrow = 1;
var pic = document.getElementById(RecordID);
if(pic){
var imageh = pic.height;
var imagew = pic.width;
if(imageh<100){
countGrow++;
imageh = imageh*1.2;
imagew = imagew*1.2;
pic.style.height = imageh + "px";
pic.style.width = imagew + "px";
var timer = window.setTimeout(function(){expander(RecordID);},2);}
}
else
{alert("error on");}
}
function shrinker(RecordID){
var pic = document.getElementById(RecordID);
if(pic){var counter = 1
var imageh = pic.height;
var imagew = pic.width;
if(imageh>20){
imageh = imageh/1.2;
imagew = imagew/1.2;
pic.style.height = imageh + "px";
pic.style.width = imagew + "px";
var timer = window.setTimeout(function(){shrinker(RecordID);},3);}
}
else
{alert("error off");}
}
//]]>
</script>
</head>
<body>
<?php
include('menuSub.html');
require_once('connect.php');
$idnum = 'phmdv06tbu';
//$q="SELECT * FROM art WHERE IDNumber = '".$idnum."'";
$q="SELECT * FROM art ORDER BY IDNumber LIMIT 4";
$r = @mysqli_query ($dbc, $q);
echo "<div class='bodyContent'><div class='imageContent'>";
if($r){
while ($row = mysqli_fetch_array($r,MYSQLI_ASSOC)){
echo "<img id='".$row['IDNumber']."' src=".$row['ImagePath']." width='5%' onMouseOver='expander(".$row['IDNumber'].");' onMouseOut='shrinker(".$row['IDNumber'].");'>";}
}
else{
echo '<div class="bodyContent"> Error<div>';
}
echo "</div></div>";
mysqli_close($dbc); ?>
</body>
</html>