FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » php/javascript question

   
Author Topic: php/javascript question
Strider
Member
Member # 1807

 - posted      Profile for Strider   Email Strider         Edit/Delete Post 
I'm having a problem with a scrolling image gallery of sorts. I have a php page that has one large gallery image and a bunch of thumbnails below it to change the corresponding larger picture. the thumbnails are all dynamically generated from a database.

I tried adding a script I found to allow the thumbnails to scroll left and right within a div of a set width to solve the problem of too many thumbnails on some pages. The problem is that it generates the images till it's the width of the div and then stops and doesn't scroll. The images still all function properly changing the corresponding gallery image, it just cuts them off at the end of the div and doesn't scroll at all.

I seperated the generated html code and dropped it into a seperate page and the scrolling works fine. I've been racking my brain and can't for the life of me figure out what's wrong. Is the fact that this is a php page interfering with the script somehow? That's the only thing I've been able to come up with as taking the generated html code and pasting it directly into another page works perfectly.

Here's an example page where it loads the pictures but doesn't scroll. The relavent code starts at the "<div id="galleryThumbnails">" line.

Here's the page I used to test the code seperately where the scrolling works fine.

Here's the javascript file that handles the scrolling.

I can post the relavent code here, but I figured it'd be easier to look at the pages directly, I'll post if anyone wants though. Any help would be greatly appreciated.

The one thing i noticed is that on my test page the visible images are constrained to the 500px width that the "motioncontainer" div is set to. While when I highlight the "motiongallery" div it seems to continue on past the end of motioncontainer to cover the length of the images. On the page from the actual site when I highlight the "motiongallery" div it's constrained to the 500px width of "motioncontainer". I'm assuming this is because the code isn't generated yet, so of course the div isn't populated with images like the the test page where I pasted the already generated html code. But how this is then relating to the non-scrolling once the code is generated, I'm not sure.

Posts: 8741 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
Strider
Member
Member # 1807

 - posted      Profile for Strider   Email Strider         Edit/Delete Post 
oops, here's the relavent php code as you won't be able to see it in the generated html page.

code:
 <div id="galleryThumbnails">
<div id="motioncontainer" style="position:relative;overflow:hidden;" align="center">
<div id="motiongallery" style="top:0; white-space: nowrap;" align="center">
<nobr id="trueContainer">
<?php
$con=mysql_connect ("localhost", "gabellin_cristof", "knollstudio")
or die ('I cannot connect to the database because: ' . mysql_error()); //connect to server

mysql_select_db("gabellin_design", $con); //open database
$result = mysql_query("SELECT * FROM Gallery WHERE Keyword='$keyword'"); //open table
$row = mysql_fetch_array($result);

$dir = dir($row['Path'] . "little/");

$y=0;
while (($file = $dir->read()) !== false)
{
switch ($file)
{
case ".":
$y--;
break;
case "..":
$y--;
break;
default:
echo "<a href=\"#\" onClick=\"return modifyimage('galleryPicture', " .$y. ")\"><img src='" . $row['Path'] .
"little/". $file . "' border='0' name='" . $file . "'></a>";
}
$y++;
}
$dir->close();

mysql_close($con);
?>
</nobr>
</div>
</div>
</div>


Posts: 8741 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
Strider
Member
Member # 1807

 - posted      Profile for Strider   Email Strider         Edit/Delete Post 
anybody? Even if it's just pointing me in the direction of some more helpful information or maybe another forum?
Posts: 8741 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
Phanto
Member
Member # 5897

 - posted      Profile for Phanto           Edit/Delete Post 
I too have a problem. I installed PHP to the computer and made .php file; it isn't automatically recognized, though. When I load it after adding the phpinfo() function, nothing happens. Any ideas?

Thanks ^_6.

Posts: 3060 | Registered: Nov 2003  |  IP: Logged | Report this post to a Moderator
El JT de Spang
Member
Member # 7742

 - posted      Profile for El JT de Spang   Email El JT de Spang         Edit/Delete Post 
I taught myself some basic php this weekend, but not nearly enough to help either of you.

I didn't even install it -- just wrote a couple of .php files, uploaded them to my website, and tested there to make sure they ran.

Posts: 5462 | Registered: Apr 2005  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Lets see . . .

First, you have an illegal element in your HTML wrapping the images: nobr. Validating HTML is important to obtaining consistent javascript DOM manipulation. I know this is present in both places, but valid HTML is much easier to debug, too.

AFAICT your problem has nothing to do with the PHP.

The most likely candidate I have right now is something in the different javascript elements trampling each other. My suggestion is to go through your page and iteratively remove parts of it until the scrolling works. Start by trying removing the extra javascript.

Phanto: link? There are several possibilities. Your page is the following, correct?

code:
<?php
phpinfo();
?>


Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Phanto
Member
Member # 5897

 - posted      Profile for Phanto           Edit/Delete Post 
Right, fugu13, with an additional command to print "hello."

The .php extension is not recognized on my computer, however, despite having installed the program.

Posts: 3060 | Registered: Nov 2003  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Installed the program? Describe in more detail the steps you took. While you can run php on a command line or such, it is almost always executed on a server. This means you must have a webserver such as Apache httpd installed, and that must have the appropriate capability to handle PHP set up.

If you are on windows, a good way to get started is to use WAMP: http://www.wampserver.com/en/ .

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Phanto
Member
Member # 5897

 - posted      Profile for Phanto           Edit/Delete Post 
I just went to that link, wamp, installed it, and did all the default values.
Posts: 3060 | Registered: Nov 2003  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
"did all the default values" isn't an explanation of the steps you took. Where did you put the file with the php code in it? What are you trying to do to view it?
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Phanto
Member
Member # 5897

 - posted      Profile for Phanto           Edit/Delete Post 
I managed to get everything to work -- for the moment at least, through wamp, which seems to be working great. Thanks, fugu13!

What would be a really good way, imo, to learn the language is a bunch of problem sets. I.e., you see some material then are given a challenge or something based on that material. This is the method I used to learn Calculus and I found it satisfying and successful. Does anyone know of any websites that provide such a format?

Thanks all [Smile] .

Posts: 3060 | Registered: Nov 2003  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
http://codekata.pragprog.com/

They're a little more oriented towards Ruby, but can be done in any language. He provides test cases for Ruby, which is a great way of validating your code.

I don't know of any PHP code katas, though if you're having particular problems with any of them I'd be happy to create some basic test cases for it.

Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Strider
Member
Member # 1807

 - posted      Profile for Strider   Email Strider         Edit/Delete Post 
quote:
The most likely candidate I have right now is something in the different javascript elements trampling each other. My suggestion is to go through your page and iteratively remove parts of it until the scrolling works. Start by trying removing the extra javascript.

Thanks fugu. I did this and figured it out. And like most problems it ended up being simple and stupid.
Posts: 8741 | Registered: Apr 2001  |  IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
No problem [Smile]
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2