Link to home
Start Free TrialLog in
Avatar of Daniish
DaniishFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Dynamic part of PHP include URL not functioning properly

Hello Experts!

I have defined a php include in my (MySQL) database as follows:
<?php include ('includes/travel_pic_thumbnails.php?poi_id=163'); ?>
...which i'm trying to use on my main site (www.globexposure.net/index.php) to display photos in a Google Maps Infowindow in conjunction with the Javascript thumbnail viewer, Highslide.
This can be seen by clicking on the Norwich (SE England) pushpin marker > arrow marker > home icon (hardcoded images) vs airplane icon (dynamic pictures loaded by php include).

The php script isn't being included however, so i have seperated the Google API code from the Highslide code to make this problem a little easier to follow. The current test site, www.globexposure.net/example-mini-gallery.php, displays a single image (as it should).
When this image is clicked, Highslide loads it and displays a controlbar for cycling through multiple images. The problem is the other images aren't being loaded by the php include, so it's not possible to cycle through them!

Initially i thought the php include itself was working well and the Highslide javascript was at fault, when in fact the Highslide forum has helped to establish that it's the other way round:
http://highslide.com/forum/viewtopic.php?t=2600&postdays=0&postorder=asc&start=0

The Highslide developer who has been helping me has got as far as diagnosing the problem as:
"Got to the cause, it's the dynamic part of the include url which seems to be the issue"
and...
"Can you try to find a different method of outputting the image links, I'm not happy with travel_pic_thumbnails script. There's a delay before images appear (the page loads first followed by the images). So I think what is happening is the include is working but it's pulling in a blank page."

This is as far as we have got - so i was hoping one you could help better explain and hopefully resolve this problem?


Many thanks for any help you can give me
Avatar of ahoffmann
ahoffmann
Flag of Germany image

> I have defined a php include in my (MySQL) database as follows:
does this mean that you generate the PHP code dynamically per request from that db?
Avatar of Daniish

ASKER

Yes i think so.

Though i have to hardcode that php include into each database record where i would like to display multiple images, because the rest of the site is written in client-side javascript, this was the only way i could think of doing it. So in this respect it's not too dynamic.
Avatar of Daniish

ASKER

MX3Design from the Highslide forum has managed to get the development site working:
www.globexposure.net/example-mini-gallery.php

BUT - he has had to drop the dynamic include. Instead his workaround is to place an index file in each photo sub-directory of /travel_pics/ - (see code snippet).

Obviously, if you can see a way that i can maintain the dynamic include that would be very much appreciated.

<?php
if ($handle = opendir('your/full/relative/path/to/includes/travel_pics/163')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".." && $file != "index.php") {
            echo "<a href=\"includes/travel_pics/163/$file\" onclick=\"return hs.expand(this, { thumbnailId: 'thumb1' })\" class=\"highslide\"><img src=\"includes/travel_pics/163/$file\" alt=\"\" /></a><br />";
        }
    }
    closedir($handle);
}
?>

Open in new window

just to be sure that I understand what you do:
  the request from the browser goes to a php page/script which queries a database which returns php code, and you want to execute that php code in your script and return the result to the browser

Is this correct?
Avatar of Daniish

ASKER

So just to clarify, the dynamic php include (see attached), which is called as follows:
<?php include ("./includes/travel_pic_thumbnails.php?poi_id=163"); ?>

has been dropped in favour of a simpler, albeit more laborious solution of using the following include:
<?php include ('includes/travel_pics/163/index.php'); ?>

...which requires the index file, as detailed in my last post, to be manually placed in each photo directory.
travel-pic-thumbnails.php.txt
Avatar of Daniish

ASKER

Yes that's right ahoffmann.
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daniish

ASKER

Assuming that i currently include the following in my database record:

<?php include ("./includes/travel_pic_thumbnails.php?poi_id=163"); ?>

how would this be coded for using eval() ?
The example code provided on php.net (see attached snippet) is still enclosed by <?php ?> tags
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
echo $str. "\n";
eval("\$str = \"$str\";");
echo $str. "\n";
?>

Open in new window

> Assuming that i currently include the following in my database record:
the database record should look like:

   include ("./includes/travel_pic_thumbnails.php?poi_id=163");

then you get this table cell and in a variable, let's say $str, then do

  eval($str);

BTW, what should the
   ?poi_id=163
do in this path? Remember that this include is a filesystem path and not a URL!
Avatar of Daniish

ASKER

So for example, a record in my database with the php include currently looks like this:

<div><a id="thumb1" href="/includes/travel_pics/163/Toby Texas Chainsaw Massacre.jpg" class="highslide" onclick="return hs.expand(this)">
<img style="float: left; margin: 0px 10px 8px 0px;" src="/includes/travel_pics/163/Toby Texas Chainsaw Massacre.jpg" width="100" height="100" alt="Highslide JS" title="Click to enlarge"/></a>
My family moved here, from College Road, when I was aged 12, after I spotted the house was for sale when we visited another further down the Close. We couldn't believe our luck when it was in our budget and this is where my folks have been based since 1992...and I dare say for a fair few years to come.
</div>
<div class="hidden-container">
<?php include ('includes/travel_pic_thumbnails.php?poi_id=163'); ?>
</div>

so how would this be encoded into a variable called $str ?

The ?poi_id=163 is passing the record 'id' in the url which is used by the travel_pic_thumbnails.php script to retrieve the relevant photos from a subfolder of /travel_pics/ that is named accordingly.

Will that still work?
dooh, as I said, you better redesign your architecture

For your example above, you need to parse what you get from the database and extract the parts being php code (those you enclosed in php tags), then eval that code and insert it again in your data.
Ugly, very ugly code ...

>  .. ?poi_id=163 is passing the record 'id' in the url
as I said: you don't have an URL here, it's a filesystem path.

Please read my suggestions carefully.
Avatar of Daniish

ASKER

OK sorry i see where your coming from now.

Personally, i would much prefer to keep my code seperate from my content and therefore not use a php include in the database, but i'm really not cluded up enough on php to know what alternative structure i could use.

In essence i need to display a single image with text pulled from mysql and when this image is clicked it uses the Javascript thumbnail viewer, Highslide, to open the image. - this i have working!

Highslide has a controlbar, which allows me to cycle through multiple images and i want it to do this for all the images that are in the same folder as the above image. The problem is the client-side Javascript can't read whats on the server, so i was trying to use php to dynamically pass the folder name that is based on the record primary key ('poi_id') back to the Highslide Javascript:
/includes/travel_pics/$poi_id/

I realise this is rather convoluted method but it's all that i could think of. Is there an obvious alternative architecture that i should consider?

Thanks again
Avatar of Daniish

ASKER

Thank you for diagnosing the issue in my code. I will ask a new question to establish how it would be better to structure my code - please respond if you have any ideas.