I have a question that I hope someone can help me with.

I have a website that I am loading dynamic content from a database.
In my files and instruction I reference the contact page, that is only because that is the file I have been testing this on.
Here is how it works:

contact page has a php text box that sends an onclick value to a javascript function.
the js functions sends the variable (q) to a php file.
that php file queries a database that has my listing in it.
the php file then echos the database values into html to the calling contact page.

The problem is that this works fine in firefox, but nothing is displayed in IE.


here is my getList.php file. This is called from the contact page.

<!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">       
<head>       
<title>lsimpson.com Beta</title>       
<meta http-equiv="Content-Type"       
content="text/html; charset=iso-8859-1" />       

<link rel="stylesheet" href="contact.css" type="text/css" />       
<script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
</head>       
<body>

//php code. this connects to the database. It receives a variable from JS 
// and uses that as a key to find the selected table item

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', '********', '********');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("*******", $con);

$sql="SELECT * FROM resi_list WHERE id = '".$q."'";

$result = mysql_query($sql);





//php code. this loops through the table based on the variable sent.

while($row = mysql_fetch_array($result))
  {


echo'<div id="imgDiv">';
echo'<div id="topimg"><img src='. $row['img1'] .' border=0></div>';
echo'<div id="botPics">';
echo'<div id="smallImg1"><img src=' . $row['img2'] . ' border=0></div>';
echo'<div id="smallImg2"><img src=' . $row['img3'] . ' border=0></div>';
echo'<div id="smallImg3"><img src=' . $row['img4'] . ' border=0></div>';
echo'</div>';
echo'</div>';


}


mysql_close($con);
?>
</body>
</html>

Here is the JS that sends the variable to the getList.php This segment of code comes from the contact.php page. You can view the entire source if you view source of the page.

{
if (str=="")
  {
  document.getElementById("imgDiv").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("imgDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getList.php?q="+str,true);
xmlhttp.send();
}

This is driving me crazy. At first I thought that the problem was my single quotes in the php echo statements, but after changing them to double quotes, and using escape (\) chars in the actualy html code, I think I ruled that out as a problem.
Also I have even tried to use html tables to make this display, and that did not work as well.

Here are the links to my site where I'm testing it at.

http://lsimpson.luskbo.com/contact.php

To replicate the problem, all you have to do is go to the page, and select the first or second option in the list box at the bottom. Only 1 and 2 work, which is correct, since that is all that is in the database. The images will change in the upper right of the page.

As you will see, it works in FF, but not IE8.

Any ideas??

Recommended Answers

All 7 Replies

dude try removing your html code in your getList.php, just remain your php code

<?php
$q=$_GET["q"];
 
$con = mysql_connect('localhost', '********', '********');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("*******", $con);
 
$sql="SELECT * FROM resi_list WHERE id = '".$q."'";
 
$result = mysql_query($sql);
 
 
 
 
 
//php code. this loops through the table based on the variable sent.
 
while($row = mysql_fetch_array($result))
  {
 
 
echo'<div id="imgDiv">';
echo'<div id="topimg"><img src='. $row['img1'] .' border=0></div>';
echo'<div id="botPics">';
echo'<div id="smallImg1"><img src=' . $row['img2'] . ' border=0></div>';
echo'<div id="smallImg2"><img src=' . $row['img3'] . ' border=0></div>';
echo'<div id="smallImg3"><img src=' . $row['img4'] . ' border=0></div>';
echo'</div>';
echo'</div>';
 
 
}
 
 
mysql_close($con);
?>

you dont need another html page inside an html page, and kindly remove the <div id="imgDiv">, coz the main page already had that div, and you dont have to create another inside of it.

echo'<div id="topimg"><img src='. $row['img1'] .' border=0></div>';
echo'<div id="botPics">';
echo'<div id="smallImg1"><img src=' . $row['img2'] . ' border=0></div>';
echo'<div id="smallImg2"><img src=' . $row['img3'] . ' border=0></div>';
echo'<div id="smallImg3"><img src=' . $row['img4'] . ' border=0></div>';
echo'</div>';

take note, ie is the most buggy in all browser, so you must be clean in you code coz ie will output incorrect results if you dont.

hope that helps

Thanks for the advice.
I only had the extra div tag there because I was wondering if it made a difference in IE.

I took the HTML out of the php script, but it still will not display the data in IE.
Works perfectly in FF.

I thought maybe there is a particular way that IE handles better?
I tried to change my php code, and while it works, it still doesn't work in IE.
Instead of using echo on every line, I just enclosed in HTML inside of the echo statement.

echo"
<div id='topimg'><img src=". $row['img1'] ." border=0></div>
<div id='botPics'>
<div id='smallImg1'><img src=" . $row['img2'] . " border=0></div>
<div id='smallImg2'><img src=" . $row['img3'] . " border=0></div>
<div id='smallImg3'><img src=" . $row['img4'] . " border=0></div>
</div>";

lol you didn't put a value fied on you option tag

<option style="width: 170px;">1</option>

changed it to

<option style="width: 170px;" value="1">1</option>

Its always the little stuff you overlook....

echo"<option style='width: 170px;'value=" . $row['id'] . ">" . $row['id'] . "</option>";

works like a charm.
Thanks alot. Now both browsers are happy.

one way of saying thanks is marking this thread solved :)

done. thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.