Sorry this is a bit long-winded - I seem to be missing a trick somewhere - I think it may be with my use of mysqli_fetch_row. I am translating an existing ASP website to PHP, and using AJAX to fetch a day's worth of images with a button onclick event. Everything seems OK, but I am seeing a 2-3 second delay from the button click to the thumbnails loading, whereas I was seeing less than 0.5 second on the original page.
The ASP action can be seen at the original site:
The PHP version is at Both versions are on the same physical server, and read the same database. Page source for the aveling3.php page (with ads etc removed for brevity):
The onclick event calls getpics.js (which is the same on both sites other than the target URL)
This populates getpics2.php
Hope you're all still with me! The thing that baffles me is that if I call the getpics2 page manually it loads almost immediately
Where am I going wrong?
PS - excuse the poor layout - my excuse is that I'm a PHP newbie
___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
The ASP action can be seen at the original site:
The PHP version is at Both versions are on the same physical server, and read the same database. Page source for the aveling3.php page (with ads etc removed for brevity):
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<body>
<!-- Header -->
<div id="hdr">
<h1>Essex Steam Aveling & Porter Steam Roller</h1>
<div class="clearer"> </div>
<!-- left column -->
<div id="lhc">
<?php include("lhc.inc"); ?>
</div>
<!-- end of left column -->
<div id="rhc">
<script type="text/javascript" src="getpic.js"></script>
<!-- right column -->
<div id="logo">
<a name="beginning"></a><a style="float:right" href="[URL unfurl="true"]http://www.essexsteam.co.uk"[/URL] title="Go to main page." ><img class="pics"src="images/logo.gif" alt="Home"/></a> <h2>Essex Steam Aveling & Porter</h2>
<h4>NEWSFLASH - The Aveling roller is now completely up and running but we sadly have decided to let it go. It is entered in <a href="[URL unfurl="true"]http://www.cheffins.co.uk/catalogue/vintage/cambridge-vintage-sale-21-0">Cheffins[/URL] July auction.</a> We look forward to seeing you there.</h4>
</div>
<hr style="clear:right"/>
<p> The Aveling & Porter 8 Ton was acquired locally in 2004. It has had
a very active life, and was ready for some maintenance. </p>
<a href="#end">Latest story</a>
<?php
$strSQL = "Select paraID, parahead, paratext, picserial From tblparas Where storyid = '1' Order by paraID";
$link = mysql_connect('**.**.**.**', 'loginname', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("steamdates");
$result = mysql_query($strSQL);
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
echo("<hr/><h4>" . $row[1] . "</h4>" . $row[2]);
$temp=$row[3];
//echo $temp;
echo("<button type='button' style='cursor:pointer' value='a$temp' id='a$temp' onclick='showpics(this.id)'>");
if ($temp < 65000)
{
echo("Show pictures");
}
echo("</button><div id='myText$temp' > </div><a href='#beginning'>TOP</a>");
echo("<div style='clear:left'> </div>");
}
mysql_free_result($result);
mysql_close($link);
?>
<a name="end"></a>
<hr/>
<div style="clear:left"> </div>
</div>
</body>
</html>
Code:
var xmlHttp
var muNum
function showpics(str)
{
muNum=str
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getpics2.php"
str=str.substr(1)
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
muNum=muNum.substr(1)
document.getElementById("myText"+muNum).innerHTML=xmlHttp.responseText
document.refresh
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
//new insert start
if (typeof DOMParser == "undefined") {
DOMParser = function () {}
DOMParser.prototype.parseFromString = function (str, contentType) {
if (typeof ActiveXObject != "undefined") {
var d = new ActiveXObject("MSXML.DomDocument");
d.loadXML(str);
return d;
} else if (typeof XMLHttpRequest != "undefined") {
var req = new XMLHttpRequest;
req.open("GET", "data:" + (contentType || "application/xml") +
";charset=utf-8," + encodeURIComponent(str), false);
if (req.overrideMimeType) {
req.overrideMimeType(contentType);
}
req.send(null);
return req.responseXML;
}
}
}
//new insert end
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
Code:
<?php
$q=$_REQUEST["q"];
$link = mysqli_connect('**.**.**.**', 'loginname', 'password','steamdates');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$sql="Select mynum,PicTitle, picpath, serialID From Pics Where PicType = '";
$sql.=$q."' order by serialid";
if ($result = mysqli_query($link, $sql)) {
$total= (mysqli_num_rows($result))-1;
while ($row = mysqli_fetch_row($result)) {
echo("<div class='thumb'><a class='pics' target='_blank' href='closeup.php?myPicID=$row[3]&myMax=$total&myPicType=$q'><img src='pics/t/$row[2]' alt='$row[1]' width='115' height='86' /></a><p> $row[1] </p> </div>");
}
}
echo("<div style='clear:both'> </div>");
mysqli_free_result($result);
mysqli_close($link);
?>
Hope you're all still with me! The thing that baffles me is that if I call the getpics2 page manually it loads almost immediately
Where am I going wrong?
PS - excuse the poor layout - my excuse is that I'm a PHP newbie
___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints