homepage Welcome to WebmasterWorld Guest from 54.161.228.29
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

This 34 message thread spans 2 pages: 34 ( [1] 2 > >     
Please Help!
Getting a slide show to work correctly...
blunick




msg:1267661
 6:45 pm on May 1, 2006 (gmt 0)

I have a PHP slide show which works great, but its doing GET statements and when the user clicks the NEXT or PREV link it post the information to the address bar so it can grab the next image.

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?

 

barns101




msg:1267662
 8:08 pm on May 1, 2006 (gmt 0)

Unless I'm missing your point entirely, it sounds like you just want a link pointing back to the first page.

blunick




msg:1267663
 2:30 am on May 2, 2006 (gmt 0)

I do want to link back...Here is what im saying ill try to be more clear, i apologize.

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.

hakre




msg:1267664
 10:12 am on May 2, 2006 (gmt 0)

well, maybe it is a solution to have the slideshow in an iframe or even a popupwindow (don't like them personally), so this will not break-up the main navigation on you site.

--hakre

blunick




msg:1267665
 1:50 pm on May 2, 2006 (gmt 0)

Yes I did do an iframe it was not pretty at all. And one of my options is to do a popup to view the larger images already...there has to be a way with PHP im thinking.

Does anyone know maybe how to get javascript:history.go(-1) to increment from -1 to -2 to -3 everytime a click is made on the site?

StupidScript




msg:1267666
 11:51 pm on May 2, 2006 (gmt 0)

Since you're okay with using Javascript (sorry, PHP thread):

<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 ... ;) )

blunick




msg:1267667
 6:10 pm on May 3, 2006 (gmt 0)

Thanks for the javasript... couple questions the code and array im generating is as follows (easy):

<?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!

StupidScript




msg:1267668
 7:01 pm on May 3, 2006 (gmt 0)

Here's where the <script> stuff comes in:

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.

blunick




msg:1267669
 9:16 pm on May 3, 2006 (gmt 0)

Ok as far as the loader

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.

StupidScript




msg:1267670
 10:00 pm on May 3, 2006 (gmt 0)

You're doing pretty well!

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.

blunick




msg:1267671
 3:37 am on May 4, 2006 (gmt 0)

Ok my first picture etc. is showing up, my next link is working too but what its doing is setting $val to the total number of images so when i click next it goes to images/11 (the $val is coming out right too which is nice)...is the java supposed to break the $val up to the actual image links?

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!

hakre




msg:1267672
 6:59 am on May 4, 2006 (gmt 0)

.is the java supposed to break the $val up to the actual image links?

if i get you question in the right way, you should be able to do this in that line:

print "img".$key.".src='images/".$val."';\n";

Also how do the (thisimg) statements come into play to be effective

you can add them to an event (onclick for example) or put it into an href, as written by StupidScript:


<a href="javascript:void getPix(currImg--)">Previous</a>
<a href="javascript:void getPix(currImg++)">Next</a>

blunick




msg:1267673
 1:44 pm on May 4, 2006 (gmt 0)

My images show its just my next and previous wont show the next or previous image:

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>

StupidScript




msg:1267674
 5:18 pm on May 4, 2006 (gmt 0)

Moving right along ... almost there!

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!)

blunick




msg:1267675
 7:02 pm on May 4, 2006 (gmt 0)

Im getting an error with apartmentImage=getElementById("$id"); I have $id calling the ID of the row. The error says "object expected"...this seems like its so close, now with this error the next and prev button just stay on the same image...Also what is this calling ThisImage=eval("img"+thisimg);

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...

StupidScript




msg:1267676
 8:40 pm on May 4, 2006 (gmt 0)

You should be getting an error ... here's why:

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?

blunick




msg:1267677
 2:31 pm on May 9, 2006 (gmt 0)

Well i really can not get this to work, ahhhhhhh its driving me crazy.

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.

StupidScript




msg:1267678
 8:21 pm on May 9, 2006 (gmt 0)

Oh man! So close ... ;)

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?

blunick




msg:1267679
 5:51 pm on May 10, 2006 (gmt 0)

Ok I see it working when i view source

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!

StupidScript




msg:1267680
 6:50 pm on May 10, 2006 (gmt 0)

Since you don't seem to be using the
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>

blunick




msg:1267681
 12:42 am on May 11, 2006 (gmt 0)

We are getting really close now this time what it did was filled in img0.src='images/11'; which 11 is the total of the images for that ID it just did not increment them it just did the total $val...the first image is showing up fine below are i++ is not incrementing, and i switched a few things around and still nothing....

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...

StupidScript




msg:1267682
 3:54 am on May 11, 2006 (gmt 0)

OH YEAH! ... programming Nirvana [en.wikipedia.org] ...

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?)

blunick




msg:1267683
 1:19 pm on May 11, 2006 (gmt 0)

well using the "===" helped our output now looks like this

<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

blunick




msg:1267684
 1:33 pm on May 11, 2006 (gmt 0)

Ok what im finding is...the code is only sticking to one line in the database, even before it was getting all the pieces of one line, now we said "===" really equal to images and it is, but only for one line, not all the images for that listing.

<?
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>

blunick




msg:1267685
 1:53 pm on May 11, 2006 (gmt 0)

WOW CLOSER THEN EVER NOW!

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!

blunick




msg:1267686
 2:03 pm on May 11, 2006 (gmt 0)

EVEN CLOSER...sorry for all the posts its the nature of coding

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...

StupidScript




msg:1267687
 3:14 am on May 12, 2006 (gmt 0)

Oh ... Javascript lords and ladies ... give me the power ...

<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.)

blunick




msg:1267688
 3:19 am on May 12, 2006 (gmt 0)

StupidScrip your the man haha....ok that was an idiot mistake on my part but GET THIS I CHANGED it back and it didn't work....

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>

StupidScript




msg:1267689
 5:28 pm on May 12, 2006 (gmt 0)

Well ... geez ... it looks pretty good. So what's happening? Are you getting Javascript errors? No errors, but broken images?

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?

blunick




msg:1267690
 8:50 pm on May 12, 2006 (gmt 0)

No the image paths are fine i know this too because the first image shows up .bmp also work fine in my browser.

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!

This 34 message thread spans 2 pages: 34 ( [1] 2 > >
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved