Forum Moderators: coopster
MY QUESTION IS: I want the user to be able to hit the back button and go right back instead of backing through ten images to get where they were before...so in essence i cant have information passed to the address bar.
ANY IDEAS OF THIS? Should i integrate PHP and java if so how? Lend me your thoughts?
On this particular site they are searching for an apartment, they search and then can click the view listing button to see the apartment and they can get all the details they want, included on this page is a mini photo album that they can click next or prevs and view all the images for that associated listing. But say they have viewed ten of the images when they click on the browser back button it takes them back through all ten pictures instead of right back to the search page where they originally came from. The reason being is i am populating the next and prevs GET statements in the address bar....
So i really dont know another way to do this, that is where im getting stuck.
<script> <? foreach($aptImages as $key => $val) { print "img".$key."=new Image();\n"; print "img".$key.".src='picture".$key.".jpg';\n"; } ?> currImg=0; function getPix(thisimg) { if ((thisimg>=1)&&(thisimg<=<?=(sizeof($aptImages)-1)?>)) { ThisImage=eval("img"+thisimg); apartmentImage.src=ThisImage.src; } else { currImg=0; apartmentImage.src=img0.src; } } </script> <img id="apartmentImage" src="picture0.jpg" /> <a href="javascript:void getPix(currImg--)">Previous</a> <a href="javascript:void getPix(currImg++)">Next</a> where:
$aptImages is an array of images unique to that listing Simple image swapping leave the history alone. Use PHP to populate the pre-loading images from a PHP array and increment/decrement with each previous/next click.
(I just winged that one ... no testing ... so ... ;) )
<?php
$id=$_GET['idnumber'];
//Need to get businessid from session
$sql = mysql_query("SELECT * FROM `apts` where aptid = '$id'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$i=0;
$build = "$row[buildid]";
}
}
$query_products = "SELECT image FROM `aptsimages` WHERE aptid = '$id' OR buildid = '$build'";
$products = mysql_query($query_products) or die(mysql_error());
$row_products = mysql_fetch_array($products);
if ($row_products > 0)
{
$images = "<img src=images/".$row_products['image']."></a>";
}
else
{
$images = "<center>Sorry there are no images for this listing</center>";
}
?>
How can i integrate right from this into the javascript i cant seem to get them to jive.
THANK SO MUCH!
if ($row_products > 0) { print "<script type='text/javascript'>\n"; if (!$firstImage) { $firstImage=$_row_products['image']; } foreach ($row_products as $key => $val) { (then that pre-loading PHP/JS code, above) } ?> (then that image-swapping JS code, above) ... </script> </head> <body> <img id="apartmentImage" src="images/<?=$firstImage?>"></a> (then the previous/next stuff, above) Use the query results to (a) identify the firstImage in the sequence and (b) populate the JS image pre-loading objects. Then use JS to (a) increment/decrement the image count and (b) swap the images.
The
$val variable (within the foreach statement) will be the .src value in the JS pre-loading sequence. Keep the object names consistent by using the $key variable (within the foreach statement) as the iterator.
foreach ($row_products as $key => $val)
{
print "img".$key."=new Image();\n";
print "img".$key.".src='picture".$key.".jpg';\n";
}
When i pull $row_products ['image'] it pulls the location of the image (ex. aptimages/image/image.gif) so in essence i need to IMG SRC to that so it will show up, i guess with what we have above is obviously not going to work. Can we point to "aptimages/image/image.gif" with this script so maybe .src=".$key."
Also would i put all this in the <head> </head>
<html>
<head>
<title>Photo Album</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?
//Need to get businessid from session
$sql = mysql_query("SELECT * FROM `apts` where aptid = '$id'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$i=0;
$build = "$row[buildid]";
}
}
$query_products = "SELECT * FROM `aptsimages` WHERE aptid = '$id' OR buildid = '$build'";
$products = mysql_query($query_products) or die(mysql_error());
$row_products = mysql_fetch_array($products);
if ($row_products > 0)
{
print "<script type='text/javascript'>\n";
}
if (!$firstImage)
{
$firstImage = $_row_products['image'];
}
foreach ($row_products as $key => $val)
{
print "img".$key."=new Image();\n";
print "img".$key.".src='picture".$key.".jpg';\n";
}
?>
<script>
currImg=0;
function getPix(thisimg) {
if ((thisimg>=1)&&(thisimg<=<?=(sizeof($row_products)-1)?>)) {
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else {
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
</head>
Thank you so much you are an awesome help.
if ($row_products > 0) { print "<script type='text/javascript'>\n"; } <= TAKE THIS OUT if (!$firstImage) { $firstImage = $_row_products['image']; } also:
foreach ($row_products as $key => $val) { print "img".$key."=new Image();\n"; print "img".$key.".src='picture".$key.".jpg';\n"; } should be:
foreach ($row_products as $key => $val) { print "img".$key."=new Image();\n"; print "img".$key.".src='[b]".$val."[/b]';\n"; } (assuming that you are storing picture file names in the database) The
.src value must be a vaild path to an image ... it doesn't matter what the image's name is because the imgN object reference is taking care of WHICH image is going to swap in. And you have an extra
<script> opening tag in there, just below the above-quoted text. You are already opening the <script> with the PHP print() function. And, yes, the
<script> goes into the head, and the <img id="apartmentImage" ... and navigation buttons go wherever you want them in the page body. Please also note that my code examples are incomplete. For instance, referencing
apartmentImage.src does no good unless you define apartmentImage using something like: apartmentImage=getElementById("apartmentImage"); So there are some holes in there that need to be patched before this will work.
Also how do the (thisimg) statements come into play to be effective
if ($row_products > 0)
{
print "<script type='text/javascript'>\n";
if (!$firstImage)
{
$firstImage = $row_products['image'];
}
foreach ($row_products as $key => $val)
{
print "img".$key."=new Image();\n";
print "img".$key.".src='images/".$val."';\n";
}
}
?>
currImg=0;
apartmentImage=getElementById("apartmentImage");
function getPix(thisimg)
{
if ((thisimg>=1)&&(thisimg<=<?=(sizeof($val)-1)?>)) {
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
Thank you for being so kind and patient this is just one of those things that is killing me ahhh!
.is the java supposed to break the $val up to the actual image links?
print "img".$key.".src='images/".$val."';\n";
Also how do the (thisimg) statements come into play to be effective
<a href="javascript:void getPix(currImg--)">Previous</a>
<a href="javascript:void getPix(currImg++)">Next</a>
Code as i have it:
if ($row_products > 0)
{
print "<script type='text/javascript'>\n";
if (!$firstImage)
{
$firstImage = $row_products['image'];
}
foreach ($row_products as $key => $val)
{
print "img".$key."=new Image();\n";
print "img".$key.".src='images/".$val."';\n";
}
}
?>
currImg=0;
apartmentImage=getElementById($firstImage);
function getPix(thisimg)
{
if ((thisimg>=1)&&(thisimg<=<?=(sizeof($val)-1)?>)) {
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage=img0.src;
}
}
</script>
</head>
<table width="151" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="151" height="55" align="center" valign="top"> <img id="apartmentImage" src="images/<?=$firstImage?>"></a>
<br>
<a href="javascript:void getPix(currImg--)">Previous</a> <a href="javascript:void getPix(currImg++)">Next</a>
</td>
</tr>
</table>
</html>
function getPix(thisimg) { // Moved into function. Object needs to be initialized // on the page before it can be referenced [b]apartmentImage=getElementById("apartmentImage");[/b] // Calculating the size of the image array if ((thisimg>=1)&&(thisimg<=<?=(sizeof([b]$row_products[/b])-1)?>)) { // Added this [b]currImg=thisimg;[/b] ThisImage=eval("img"+thisimg); apartmentImage.src=ThisImage.src; } else { currImg=0; apartmentImage[b].src[/b]=img0.src; } } And let's make this a little more tidy:
<a href="javascript:void getPix(currImg-1)">Previous</a> <a href="javascript:void getPix(currImg+1)">Next</a> (Still not tested ... sorry!)
currImg=0;
function getPix(thisimg)
{apartmentImage=getElementById("$id");
if((thisimg>=1)&&(thisimg<=<?=(sizeof($row_products)-1)?>))
{
currImg=thisimg;ThisImage=eval("img"+thisimg);apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
Gosh JAVA is baby steps for me lol...
getElementById([i]"objbectId"[/i]) is a Javascript function that looks for an initialized object with an id=objectId attribute. In this case, we want Javascript to access an IMG object with a very specific
id= ... the one with the id="apartmentImage". We're telling Javascript to "get that page element with an id of 'apartmentImage' and change its
src= attribute from whatever it once was to this new src= value". apartmentImage=getElementById("apartmentImage"); is assigning a value to the Javascript variable
apartmentImage, and that value equals the object reference provided by the getElementById("apartmentImage") function. In other words (and NOT to be used):
apartmentImage=document.images.apartmentImage Don't use the PHP
$id variable ... you specifically want to swap whatever the src= attribute value is for the <img id="apartmentImage" src=... with an image being referenced from within the img0.src... group of objects that were defined by the pre-loading code. Previous = "1" = img1.src = "images/apt5678-1.gif"
Current = "2" = img2.src = "images/apt5678-2.gif"
Next = "3" = img3.src = "images/apt5678-2.gif"
(or whatever the image names are)
ThisImage=eval("img"+thisimg); is doing something very similar to getElementById() in that it is assigning a value to the Javascript ThisImage variable. The value that is being assigned is a reference to the object identified by the string img PLUS the numerical value being passed to the function by the Previous or Next click: ThisImage=eval("img2"); for example. This allows us to reference the object group created by the pre-loading code.
Here's a really twisted look:
imageObjectReference.src = preLoadedObjectReference.src Yes?
Here is what i have as code so far:
<html>
<head>
<title>Photo Album</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?
include('include.php');
$id='5973';
//Need to get businessid from session
$sql = mysql_query("SELECT * FROM `apts` where aptid = '$id'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$i=0;
$build = "$row[buildid]";
}
}
$query_products = "SELECT * FROM `aptsimages` WHERE aptid = '$id' OR buildid = '$build'";
$products = mysql_query($query_products) or die(mysql_error());
$row_products = mysql_fetch_array($products);
if ($row_products > 0)
{
print "<script type='text/javascript'>\n";
if (!$firstImage)
{
$firstImage = $row_products['image'];
$id = $row_products['id'];
}
foreach ($row_products as $key => $val)
{
print "img".$key."=new Image();\n";
print "img".$key.".src='images/".$val."';\n";
}
}
?>
currImg=0;
function getPix(thisimg)
{
apartmentImage=getElementById("apartmentImage");
if((thisimg>=1)&&(thisimg<=<?=(sizeof($row_products)-1)?>))
{
currImg=thisimg;
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
</head>
<table width="151" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="151" height="55" align="center" valign="top"> <img id="apartmentImage" src="images/<?=$firstImage?>"></a>
<br>
<a href="javascript:void getPix(currImg-1)">Previous</a> <a href="javascript:void getPix(currImg+1)">Next</a>
</td>
</tr>
</table>
</html>
I just dont think its finding my images right...does each image need to be numbered like (apt1.jpg, apt2.jpg) because all my images are a different name but still are associated with an apt id.
About the only thing I see in your code is this:
if ($row_products > 0) should be:
if (sizeof($row_products) > 0) because
$row_products is an array. When you load this page into your browser, check out the page source code and look for the Javascript section. It should look something like this:
img0 = new Image(); img0.src = "images/someKitchenview.jpg"; img1 = new Image(); img1.src = "images/backyard-00034.gif"; etc. One pair for each image in the database related to that apartment id. The path and file name information must be correct, or else Javascript won't be able to assign the proper value to that particular Image object's
src property. You can't add the path info later, because this is where JS gets the images and loads them into memory. And that's about it. Are you receiving any Javascript errors, or is it just that the Previous and Next images are broken and won't load?
Here is what is happening though this is the view source from the page:
<script type='text/javascript'>
img0=new Image();
img0.src='images/11';
imgid=new Image();
imgid.src='images/11';
img1=new Image();
img1.src='images/image/jpeg';
imgimage_type=new Image();
imgimage_type.src='images/image/jpeg';
img2=new Image();
img2.src='images/aptsimages/364_92g1.jpg';
imgimage=new Image();
imgimage.src='images/aptsimages/364_92g1.jpg';
img3=new Image();
img3.src='images/16179';
imgimage_size=new Image();
imgimage_size.src='images/16179';
img4=new Image();
img4.src='images/144';
imgbuildid=new Image();
imgbuildid.src='images/144';
img5=new Image();
img5.src='images/';
imgaptid=new Image();
imgaptid.src='images/';
img6=new Image();
img6.src='images/';
imgownid=new Image();
imgownid.src='images/';
currImg=0;
function getPix(thisimg)
{
apartmentImage=getElementById("apartmentImage");
if((thisimg>=1)&&(thisimg<=13))
{
currImg=thisimg;
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
It grabbing all the attributes that are part of one row in the database, as you can see up top its grabbing, ID, Image_Type, Image_Size those are all fields in my table. So it grabbing those not the next image in succession. HAHA kind of weird, also the next and preve are not switching to those img1.src etc. Any thoughts? Thanks so much as always!
image_type or id fields, you may want to restrict your query to grabbing only the image field where the id matches. However, using your original query (
*), try this in the PHP section: if (sizeof($row_products) > 0) { print "<script type='text/javascript'>\n"; if (!$firstImage) { $firstImage = $row_products['image']; $id = $row_products['id']; } [b]$i=0;[/b] foreach ($row_products as $key => $val) { [b]if ($key=="image") {[/b] print "img".$i."=new Image();\n"; print "img".$i.".src='images/".$val."';\n"; [b]$i++;[/b] [b]}[/b] } } and this in the JS getPix() function:
if ((thisimg>=1)&&(thisimg<=<?=[b]($i-1)[/b]?>)) (JS seems to prefer two operators ...
<= not < ) Should result in page source code something like:
<html> <head> <title>Page Title</title> <script type='text/javascript'> img0=new Image(); img0.src='images/aptsimages/364_92g1.jpg'; img1=new Image(); img1.src='images/aptsimages/374_96g1.jpg'; img2=new Image(); img2.src='images/aptsimages/388_94g1.jpg'; currImg=0; function getPix(thisimg) { apartmentImage=getElementById("apartmentImage"); if((thisimg>=1)&&(thisimg<=2)) { currImg=thisimg; ThisImage=eval("img"+thisimg); apartmentImage.src=ThisImage.src; } else { currImg=0; apartmentImage.src=img0.src; } } </script> </head> <body> <table width="151" border="0" cellpadding="0" cellspacing="0"> <!--DWLayoutTable--> <tr> <td width="151" height="55" align="center" valign="top"> <!-- ### IMG SHOULD BE FIRST ONE IN THE DB FOR THIS ID ### --> <img id="apartmentImage" src="images/[b]aptsimages/364_92gl.jpg[/b]"></a> <br> <!-- ### (currImage-1) = -1 = img0.src ; (currImage+1) = 1 = img1.src ### --> <a href="javascript:void getPix(currImg-1)">Previous</a> <a href="javascript:void getPix(currImg+1)">Next</a> </td> </tr> </table> </body> </html>
VIEWED SOURCE:
<html>
<head>
<title>Photo Album</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type='text/javascript'>
img0=new Image();
img0.src='images/11';
img1=new Image();
img1.src='images/aptsimages/364_92g1.jpg';
currImg=0;
function getPix(thisimg)
{
apartmentImage=getElementById("apartmentImage");
if ((thisimg>=1)&&(thisimg<=1))
{
currImg=thisimg;
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
</head>
<table width="151" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="151" height="55" align="center" valign="top"> <img id="apartmentImage" src="images/aptsimages/364_92g1.jpg"></a>
<br>
<a href="javascript:void getPix(currImg-1)">Previous</a> <a href="javascript:void getPix(currImg+1)">Next</a>
</td>
</tr>
</table>
</html>
SO CLOSE I CAN FEEL IT...
img0=new Image(); img0.src='images/11'; img1=new Image(); img1.src='images/aptsimages/364_92g1.jpg'; Whtever is working here must be repeated for each increment.
I can't help but think that it's the image name (img1.src) that's working.
$i++ should be incrementing, and you shouldn't need to hard-code it. if ($key=="image") { should be restricting the iteration/increment.
According to a recent post:
img0=new Image(); img0.src='images/11'; imgid=new Image(); imgid.src='images/11'; img1=new Image(); img1.src='images/image/jpeg'; imgimage_type=new Image(); imgimage_type.src='images/image/jpeg'; img2=new Image(); img2.src='images/aptsimages/364_92g1.jpg'; imgimage=new Image(); imgimage.src='images/aptsimages/364_92g1.jpg'; This says that the
$row_products array consists of: 0 => 11 , id => 11 , 1 => image/jpeg , image_type => image/jpeg , 2 => aptsimages/364_92g1.jpg , image => aptsimages/364_92g1.jpg which indicates that:
if ($key=="image") { print "img".$i."=new Image();\n"; print "img".$i.".src='images/".$val."';\n"; $i++; } should only "key" off of the "image" array element.
Try:
if ($key==="image") { This strikes me as a common, sloppy (mine) programming error in PHP.
(Does anyone want to comment on the difference between
== ["equals"] comparison operator and === ["really equals"] comparison operator?)
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/364_92g1.jpg';
currImg=0;
function getPix(thisimg)
{
apartmentImage=getElementById("apartmentImage");
if ((thisimg>=1)&&(thisimg<=0))
{
currImg=thisimg;
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
</head>
We just are not getting all images in the loop...hmmm
<?
include('include.php');
$id='5973';
//Need to get businessid from session
$sql = mysql_query("SELECT * FROM `apts` where aptid = '$id'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$i=0;
$build = "$row[buildid]";
}
}
$query_products = "SELECT * FROM `aptsimages` WHERE aptid = '$id' OR buildid = '$build'";
$products = mysql_query($query_products) or die(mysql_error());
$row_products = mysql_fetch_array($products);
if (sizeof($row_products) > 0) {
print "<script type='text/javascript'>\n";
if (!$firstImage) {
$firstImage = $row_products['image'];
$id = $row_products['id'];
}
$i=0;
foreach($row_products as $key => $val) {
if ($key==="image") {
print "img".$i."=new Image();\n";
print "img".$i.".src='images/".$val."';\n";
$i++;
}
}
}
?>
currImg=0;
function getPix(thisimg)
{
apartmentImage=getElementById("apartmentImage");
if ((thisimg>=1)&&(thisimg<=<?=($i+1)?>))
{
currImg=thisimg;
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
Ok I added in a while loop to get our images: here is my code...
<?
include('include.php');
$id='5973';
//Need to get businessid from session
$sql = mysql_query("SELECT * FROM `apts` where aptid = '$id'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$i=0;
$build = "$row[buildid]";
}
}
$query_products = "SELECT * FROM `aptsimages` WHERE aptid = '$id' OR buildid = '$build'";
$products = mysql_query($query_products) or die(mysql_error());
while($row_products = mysql_fetch_array($products)){
$i=0;
if (sizeof($row_products) > 0) {
print "<script type='text/javascript'>\n";
if (!$firstImage) {
$firstImage = $row_products['image'];
$id = $row_products['id'];
}
foreach($row_products as $key => $val) {
if ($key==="image") {
print "img".$i."=new Image();\n";
print "img".$i.".src='images/".$val."';\n";
$i++;
}
}
}
}
?>
currImg=0;
function getPix(thisimg)
{
apartmentImage=getElementById("apartmentImage");
if ((thisimg>=1)&&(thisimg<=<?=($i-1)?>))
{
currImg=thisimg;
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
Now HERE IS THE VIEW SOURCE:
<html>
<head>
<title>Photo Album</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/364_92g1.jpg';
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/364_92g2.jpg';
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/364_92g3.jpg';
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/364_92g4.jpg';
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/364_92g5.jpg';
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/364_92g.jpg';
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/363_beau1.jpg';
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/363_beau2.jpg';
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/363_beau3.jpg';
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/363_beau4.jpg';
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/363_beau5.jpg';
currImg=0;
function getPix(thisimg)
{
apartmentImage=getElementById("apartmentImage");
if ((thisimg>=1)&&(thisimg<=0))
{
currImg=thisimg;
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
</head>
<table width="151" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="151" height="55" align="center" valign="top"> <img id="apartmentImage" src="images/aptsimages/364_92g1.jpg"></a>
<br>
<a href="javascript:void getPix(currImg-1)">Previous</a> <a href="javascript:void getPix(currImg+1)">Next</a>
</td>
</tr>
</table>
</html>
OUR img0.SRC is not going to img1.src, img2.src....I CAN TASTE IT NOW HAHA!
Here is my code:
<?
include('include.php');
$id='4882';
//Need to get businessid from session
$sql = mysql_query("SELECT * FROM `apts` where aptid = '$id'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$i=0;
$build = "$row[buildid]";
}
}
$query_products = "SELECT * FROM `aptsimages` WHERE aptid = '$id' OR buildid = '$build'";
$products = mysql_query($query_products) or die(mysql_error());
print "<script type='text/javascript'>\n";
while($row_products = mysql_fetch_array($products))
{
//$i=0;
if (sizeof($row_products) > 0)
{
if (!$firstImage)
{
$firstImage = $row_products['image'];
$id = $row_products['id'];
}
foreach($row_products as $key => $val)
{
if ($key==="image")
{
print "img".$i."=new Image();\n";
print "img".$i.".src='images/".$val."';\n";
$i++;
}
}
}
}
?>
currImg=0;
function getPix(thisimg)
{
apartmentImage=getElementById("apartmentImage");
if ((thisimg>=1)&&(thisimg<=<?=($i-1)?>))
{
currImg=thisimg;
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
VIEW SOURCE:
<html>
<head>
<title>Photo Album</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/4882_1.bmp';
img1=new Image();
img1.src='images/aptsimages/4882_2.bmp';
img2=new Image();
img2.src='images/aptsimages/4882_3.bmp';
img3=new Image();
img3.src='images/aptsimages/4882_4.bmp';
img4=new Image();
img4.src='images/aptsimages/4882_5.bmp';
img5=new Image();
img5.src='images/aptsimages/4882_6.bmp';
img6=new Image();
img6.src='images/aptsimages/4882_7.bmp';
img7=new Image();
img7.src='images/aptsimages/4882_8.bmp';
img8=new Image();
img8.src='images/aptsimages/4882_9.bmp';
img9=new Image();
img9.src='images/aptsimages/4882_10.bmp';
img10=new Image();
img10.src='images/aptsimages/4882_11.bmp';
img11=new Image();
img11.src='images/aptsimages/4882_12.bmp';
currImg=0;
function getPix(thisimg)
{
apartmentImage=getElementById("apartmentImage");
if ((thisimg>=1)&&(thisimg<=11))
{
currImg=thisimg;
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
</head>
<table width="151" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="151" height="55" align="center" valign="top"> <img id="apartmentImage" src="images/aptsimages/4882_1.bmp"></a>
<br>
<a href="javascript:void getPix(img.src-1)">Previous</a> <a href="javascript:void getPix(img.src+1)">Next</a>
</td>
</tr>
</table>
</html>
LAST PROBLEM our next and previous wont go...this is when i need your java power like never before...
<a href="javascript:void getPix([b]img.src[/b]-1)">Previous</a> <a href="javascript:void getPix([b]img.src[/b]+1)">Next</a> should be
<a href="javascript:void getPix([b]currImg[/b]-1)">Previous</a> <a href="javascript:void getPix([b]currImg[/b]+1)">Next</a> Thank you, lords and ladies! ;)
(
currImg is a number. That number gets evaluated with the string, img, to form an Image object reference, like img9. In your code, you have used the .src parameter of the uninitialized img object (no number added) ... and that .src parameter is not a number, and therefore cannot create a valid object reference.)
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
Here is my view source...i can taste sweet victory haha
<html>
<head>
<title>Photo Album</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type='text/javascript'>
img0=new Image();
img0.src='images/aptsimages/4882_1.bmp';
img1=new Image();
img1.src='images/aptsimages/4882_2.bmp';
img2=new Image();
img2.src='images/aptsimages/4882_3.bmp';
img3=new Image();
img3.src='images/aptsimages/4882_4.bmp';
img4=new Image();
img4.src='images/aptsimages/4882_5.bmp';
img5=new Image();
img5.src='images/aptsimages/4882_6.bmp';
img6=new Image();
img6.src='images/aptsimages/4882_7.bmp';
img7=new Image();
img7.src='images/aptsimages/4882_8.bmp';
img8=new Image();
img8.src='images/aptsimages/4882_9.bmp';
img9=new Image();
img9.src='images/aptsimages/4882_10.bmp';
img10=new Image();
img10.src='images/aptsimages/4882_11.bmp';
img11=new Image();
img11.src='images/aptsimages/4882_12.bmp';
currImg=0;
function getPix(thisimg)
{
apartmentImage=getElementById("apartmentImage");
if ((thisimg>=1)&&(thisimg<=11))
{
currImg=thisimg;
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
</head>
<table width="151" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="151" height="55" align="center" valign="top"> <img id="apartmentImage" src="images/aptsimages/4882_1.bmp"></a>
<br>
<a href="javascript:void getPix(currImg-1)">Previous</a> <a href="javascript:void getPix(currImg+1)">Next</a>
</td>
</tr>
</table>
</html>
There is really only one thing that stands out, and that's the path to your images.
Is
'images/aptsimages/4882_1.bmp' actually correct (and can your browser handle .BMP images)? It's definitely not '../images/aptsimages/4882_1.bmp' or 'aptsimages/4882_1.bmp' or something?
When i click next or previous it stays on the first image and does not go anywhere at all oddly enough.
Internet explorer is saying an error of object expected and its pointing to the line: apartmentImage=getElementById("apartmentImage");
Here is my full script as i have it too:
<html>
<head>
<title>Photo Album</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?
include('include.php');
$id='4882';
//Need to get businessid from session
$sql = mysql_query("SELECT * FROM `apts` where aptid = '$id'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
$i=0;
$build = "$row[buildid]";
}
}
$query_products = "SELECT * FROM `aptsimages` WHERE aptid = '$id' OR buildid = '$build'";
$products = mysql_query($query_products) or die(mysql_error());
print "<script type='text/javascript'>\n";
while($row_products = mysql_fetch_array($products))
{
//$i=0;
if (sizeof($row_products) > 0)
{
if (!$firstImage)
{
$firstImage = $row_products['image'];
$id = $row_products['id'];
}
foreach($row_products as $key => $val)
{
if ($key==="image")
{
print "img".$i."=new Image();\n";
print "img".$i.".src='images/".$val."';\n";
$i++;
}
}
}
}
?>
currImg=0;
function getPix(thisimg)
{
apartmentImage=getElementById("apartmentImage");
if ((thisimg>=1)&&(thisimg<=<?=($i-1)?>))
{
currImg=thisimg;
ThisImage=eval("img"+thisimg);
apartmentImage.src=ThisImage.src;
}
else
{
currImg=0;
apartmentImage.src=img0.src;
}
}
</script>
</head>
<table width="151" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="151" height="55" align="center" valign="top"> <img id="apartmentImage" src="images/<?=$firstImage?>"></a>
<br>
<a href="javascript:void getPix(currImg-1)">Previous</a> <a href="javascript:void getPix(currImg+1)">Next</a>
</td>
</tr>
</table>
</html>
That damn javascript hahaha!