Google Answers Logo
View Question
 
Q: Simple (I think) PHP coding ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Simple (I think) PHP coding
Category: Computers > Programming
Asked by: thewolf1-ga
List Price: $10.00
Posted: 17 Aug 2005 17:25 PDT
Expires: 16 Sep 2005 17:25 PDT
Question ID: 556996
I'm a C++ programmer since 1.5 years. Before that (and still) I coded
in Delphi. I should be able to understand your answer... :)

I have a personal website on wich I have a gallery. Each image is a
clickable thumbnail. When I click on one of them, I want a PHP
function to be fired. The function must generate a simple HTML page on
wich is the full size image and a description. The PHP function must
be in one external file.

I tried something like that so far (that code is in ViewImg.php):

<?php
function ViewImage($ImgURL, $ImgDesc)
{
   echo "<html>";
   echo "<head>";
   echo "<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=windows-1252\">";
   echo "<title></title>";
   echo "</head>";
   echo "<body>";
   echo "<img src=\"${ImgURL}\" border=\"0\" alt=\"\">";
   echo "Desription: ${ImgDesc}";
   echo "</body>";
   echo "</html> ";
}
?>

How do I generate a full dynamic HTML page from a PHP function and how
I use it from my HTML code?

Clarification of Question by thewolf1-ga on 17 Aug 2005 17:26 PDT
By the way this is my fist attempt at PHP...

Request for Question Clarification by palitoy-ga on 18 Aug 2005 01:32 PDT
Hello thewolf1-ga

Can you provide me with a few more pieces of information?

1) Is the page with the thumbnails on it a .php or .html page?
2) Where do the $ImgURL and $ImgDesc variables come from?
3) How are the $ImgURL and $ImgDesc variables being passed to your
ViewImage function?
4) Can you provide the HTML code for the thumbnail section of your webpage?

With these pieces of information I will be able to provide you with a
working solution.

Clarification of Question by thewolf1-ga on 18 Aug 2005 05:18 PDT
1) HTML
2-3) Those vars must be assigned by the calling thumbnails (within the
HREF image link).
4) See http://wolfcast.com/avaliquette/professional.html for actual gallery.

<A HREF="images/professionnal/BLD04.jpg"><IMG
SRC="images/professionnal/BLD04Small.gif" WIDTH="73" HEIGHT="100"
ALT="" BORDER="0"></A>

would become something like:

<A HREF=[call to PHP ViewImage("apic.jpg", "a desc")]><IMG
SRC="images/professionnal/BLD04Small.gif" WIDTH="73" HEIGHT="100"
ALT="" BORDER="0"></A>

So by clicking on a thumbnail, a whole new dynamic HTML page is
created on the fly...

Request for Question Clarification by palitoy-ga on 18 Aug 2005 06:40 PDT
Because the page you are calling from is HTML, the easiest way to pass
the variables to another page would be to use a form and POST them. 
The PHP page would then pick up the POST variables and display them on
a page.

I can supply an answer which would provide an example of this for you
to edit further.  Would this be an acceptable answer for you?

Clarification of Question by thewolf1-ga on 18 Aug 2005 06:57 PDT
I know I would be able to do this with 2 edits and a submit button on
my HTML, but I want the function to be called from my HTML without
user intervention (except the click on the thumbnail).

If your solution does not requires any user intervention, and is
without edits & button it's all OK.

Request for Question Clarification by palitoy-ga on 18 Aug 2005 07:12 PDT
The form can be submitted with a little javascript and a single click
on the image.  Because your page is an HTML it cannot execute PHP code
directly.

Can you also explain what you mean by "edits"?  I want to provide you
with a solution but without clarification on this I may not be able
to.

In brief, my summary would provide you with a solution where the user
clicks on a thumbnail and a "php page" would be opened that contained
the image and description of the thumbnail the user clicked on.  Only
one "php page" will be required as it will be reused for each image.

Clarification of Question by thewolf1-ga on 18 Aug 2005 07:21 PDT
An edit box... Where you put your search query on www.google.com is an edit.

As long the JavaScript isn't blocked by Windows XP with SP2 everything
is fine with me.
Answer  
Subject: Re: Simple (I think) PHP coding
Answered By: palitoy-ga on 18 Aug 2005 08:09 PDT
Rated:5 out of 5 stars
 
Hello thewolf1-ga

Here is the solution as requested in the clarification above.  

The javascript will not be blocked by Windows XP but your visitors
should have javascript enabled in their browsers for this method to
work.

In your HTML page paste the following into the <head> tag:

<script>
function view_image (vImage,vDesc) {
document.imageform.vImage.value = vImage;
document.imageform.vDesc.value = vDesc;
document.imageform.submit();
};
</script>

When a thumbnail is clicked this javascript function is called, it
takes the image location and description and places them in the hidden
form variables before finally submitting the form and creating the
page.

Next you need to paste the following form somewhere after the <body>
tag in your HTML page:

<form action="image_view.php" method="post" name="imageform" target="_blank">
<input name="vImage" type="hidden" />
<input name="vDesc" type="hidden" />
</form>

This form submits results to image_view.php and opens the page up in a
new browser window.  The form has two hidden fields which hold the
image location and description when the form is submitted.

Each thumbnail image should then have code similar to this:

<a href="#" onclick="view_image('this is the url of the image','this
is the description of the image');">
<img src="thumbnail.png" alt="thumbnail" title="thumbnail" />
</a>

You should also create a file called image_view.php and place this in
the same directory as your HTML file (this can be moved if you change
the location in the form tag).  This file should contain:

<?
$image_to_show = $_POST['vImage'];
$description_to_print = $_POST['vDesc'];
echo "<html>";
echo "<head>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=windows-1252\">";
echo "<title></title>";
echo "</head>";
echo "<body>";
echo "<img src=\"$image_to_show\" border=\"0\" alt=\"\">";
echo "Desription: $description_to_print";
echo "</body>";
echo "</html> ";
?>

If you have any questions regarding this solution please ask for
clarification and I will do my best to respond swiftly.

Request for Answer Clarification by thewolf1-ga on 18 Aug 2005 16:15 PDT
Unfortunatly it's not working, but I think it's close...

See http://wolfcast.com/avaliquette/professional.html for result...

The first <script> part (in <head> tag) is the cause IMO...

Request for Answer Clarification by thewolf1-ga on 18 Aug 2005 16:20 PDT
Please discard my last clarification... It's totaly working :)

My <SCRIPT> was ended with </SCRIPTt>

d'oh!

Thanks a lot !

Clarification of Answer by palitoy-ga on 18 Aug 2005 23:24 PDT
Glad you got it working!  If you have any further queries please let me know.
thewolf1-ga rated this answer:5 out of 5 stars
Exactly what I wanted! Hope it wasen't too difficult :)

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy