First, I want to thank those who have helped me with binary blobs in the past. I have had alot of help from this forum. My problems (for those who have seen my previos posts) ended up being the blob data stored in the database being corrupt.
With that fixed....everything is now working....although the images are displaying VERY VERY slow.
Basically, my scripts are pulling a binary blob from an sql database and displaying 10 thumbnails. They are taking forever to display. Can you glance at my code and offer a suggestion as too why they can so long? I am learning php and cant seem to figure out this puzzle.
The code that display's the blob is this:
<?php
ob_start(); // turn output buffering on
// open the database and retrieve the record
(!($dbh=mysql_connect ("xxx", "xxxx", "xxx")));
(!mysql_select_db("xxx",$dbh));
$query = "SELECT medium_photo FROM residential WHERE Id = $Id";
(!($result = @ mysql_query ($query, $dbh)));
$data = @mysql_fetch_array($result);
$image = $data["medium_photo"];
header("Content-Type: image/jpeg");
echo $image;
ob_end_flush();
?>
The 'main code' is this:
<?php
session_start();
$this_document = $_SERVER['newcode.php'];
$db_addr = 'xxx'; // address of MySQL server.
$db_user = 'xxx'; // Username to access server.
$db_pass = 'xxx'; // Password access server.
$db_name = 'xxx'; // Name of database to connect to.
$connect = @mysql_connect("$db_addr", "$db_user", "$db_pass");
$page = $_GET['page'];
$limit = $_GET['limit'];
if (!($connect)) // If no connect, error and exit().
{
echo("<p>Unable to connect to the database server.</p>");
exit();
}
if (!(@mysql_select_db($db_name))) // If can't connect to database, error and exit().
{
echo("<p>Unable to locate the $db_name database.</p>");
exit();
}
if (!($limit)){
$limit = 10;} // Default results per-page.
if ( !$page or $page < 0 ) { $page = 0; } // Default page value.
$numresults = mysql_query("SELECT town, list_price, bedrooms, baths, rooms, Id ,IF (lister_office_name like 'Century', 1, 0)
AS featured
FROM residential
WHERE town = '$selecttown' OR '$selecttown2'"); // the query.
$numrows = mysql_num_rows($numresults); // Number of rows returned from above query.
if ($numrows == 0){
echo("No results found matching your query"); // modify the "Not Found" error for your needs.
exit();}
$pages = intval($numrows/$limit); // Number of results pages.
// $pages now contains int of pages, unless there is a remainder from division.
if ($numrows % $limit) {
$pages++;} // has remainder so add one page
$current = intval($page/$limit) + 1; // Current page number.
if (($pages < 1)) {
$total = 1;} // If $pages is less than one, total pages is 1.
else {
$total = $pages;} // Else total pages is $pages value.
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
else{
$last = $numrows;} // If last results page, last result equals total number of results.
//escape from PHP mode.
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
include("head.html");
?>
<table width="100%" border="0" cellpadding="2">
<!--DWLayoutTable-->
<tr>
<td width="323" align="left"><font size="1" face="Arial, Helvetica, sans-serif">Results
per-page: <a href="<?=$this_document?>?query=<?=$query?>&page=<?=$page?>&limit=5">5</a>
| <a href="<?=$this_document?>?query=<?=$query?>&page=<?=$page?>&limit=10">10</a>
| <a href="<?=$this_document?>?query=<?=$query?>&page=<?=$page?>&limit=20">20</a>
| <a href="<?=$this_document?>?query=<?=$query?>&page=<?=$page?>&limit=50">50</a></font><font face="Arial, Helvetica, sans-serif">
</font>
<br>
</td>
<td colspan="2" align="left"><font size="2" face="Arial, Helvetica, sans-serif"> </font></td>
</tr>
<tr>
<td align="left"><font size="2" face="Arial, Helvetica, sans-serif">Showing
listings <b>
<?=$first?>
</b> - <b>
<?=$last?>
</b> of <b>
<?=$numrows?>
</b></font>for <b><i><?php print $selecttown?></b></i><br><a href="newsearch.php">Click Here</a> to change your search criteria.</td>
</td>
<td align="left"></td>
<td width="324" align="left">
<p align="right"><font size="2" face="Arial, Helvetica, sans-serif"> </font><font size="2" face="Arial, Helvetica, sans-serif">Page
<b>
<?=$current?>
</b> of <b>
<?=$total?>
</b></font></p>
</td>
</tr>
<tr>
<td colspan="3" align="left" valign="top"><font size="2" face="Arial, Helvetica, sans-serif"> </font>
<div align="left"><font size="2" face="Arial, Helvetica, sans-serif"></font></div>
<font size="3" face="Arial, Helvetica, sans-serif"><center>
<?
//$limitnum = 15;
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$this_document?query=$query&page=$back_page&limit=$limit\">Back</a>\n");}
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b>\n");} // If current page don't give link, just text.
//elseif ($ppage < $page - $limitnum || $ppage > $page + $limitnum){}
else{
echo("<a href=\"$this_document?query=$query&page=$ppage&limit=$limit\">$i</a>\n");}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo(" <a href=\"$this_document?query=$query&page=$next_page&limit=$limit\">Next</a>");}
?>
</font></center></td>
</tr>
<tr>
<td colspan="3" align="left"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td colspan="3" align="left">
<?
//Go back into PHP mode.
// Now we can display results
$results = mysql_query("SELECT * ,IF (lister_office_name like 'Century 21 Highview Realty', 1, 0)
AS featured
FROM residential
WHERE town = '$selecttown'
ORDER BY featured DESC, list_price DESC
LIMIT $page, $limit");
for($i = 0; $i < $limit; $i++){
for ($count = 1; $row = mysql_fetch_assoc ($results);++$count)
{
if ($count & 1) {
$color = "#FFFFFF";
$font = "white";
}
else {
$color = "#FFFFCC";
$font = "black";
}
$printthis = "
<table border=0 width=100% cellspacing=0 cellpadding=0>
<tr>
<td bgcolor=$color align=center>
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<td width=100%><b>Bedrooms: </b>$row[bedrooms]</td>
</tr>
<tr>
<td width=100%><b>Bathrooms: </b>$row[baths]</td>
</tr>
</table>
</td>
<td bgcolor=$color>
<div align=center>
<center>
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<td width=100%>$row[town]</td>
</tr>
<tr>
<td width=100%><b>MLS #</b>$row[Id]</td>
</tr>
</table>
</center>
</div>
</td>
<td bgcolor=$color>
<div align=center>
<center>
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<td width=100%><a href=displayprop.php?Id=$row[Id]> Click Here for more info</a></td>
</tr>
<tr>
<td width=100%><b>$ $row[list_price].00</b></td>
</tr>
</table>
</center>
</div>
</td>
</tr>
</table>
";
?>
<table border=0 width=100% cellspacing=0 cellpadding=0>
<tr>
<td>
<a href=displayprop.php?Id=<? echo $row[Id]; ?>>
<img src="getthumb.php?Id=<?= $row['Id'] ?>" width=100 height=65>
</a>
</td>
<td width="100%">
<?
print $printthis;
?>
</td>
</tr>
</table>
<hr color=#D7DC0C noshade>
<?
}
}
?>
</td>
</tr>
</table>
<?php
include("foot.html");
?>
</body>
</html>
I am not sure if it is because we are loading 10 images? Or is it slow because we are loading 10 images from 10 calls to a cgi script? Or is it slow because we are doing 10 cgi calls that each does a database lookup?
I am not sure how to fix this problem....any help would be VERY appreciated.