+ Reply to Thread
Results 1 to 9 of 9

Thread: transferring dynamic data

  1. #1
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Question transferring dynamic data

    I'm looking to send data to another region of the page. To be more exact I would like that when an image is clicked the id of that image will be sent to a separate region of the same screen and later (with other information) will be sent on to me so that I can identify which image the user selected. I think it's not so tough but I just can't think of the best way of doing it although I'm pretty sure it requires JS. Any help will be appreciated.

  2. #2
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: transferring dynamic data

    It could be done using JS, but there would be no way of getting the actual data to you. You would need either server side scripting or an outside service to email the results to you.
    If there is only one choice the user has when selecting an image (ie, they click an image, and you get told which image is clicked) then you don't even need to use JavaScript.
    If the user can select multiple images and then submit them as a list or w/e, then JS is the best way here.

    If you only need the one image, you can use PHP in addition to your HTML image.
    In the page with the images, use this code for each image:
    Code:
    <a href='results.php?image=1' border='0'><img src='picture1.png' alt='1st picture'></a>
    Yes, it's just a picture link to a PHP page.
    Next, create a new file in the same directory called results.php.
    In it, put this:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    
    <html><head>
    <title>Image Selected.</title>
    </head><body>
    <p>
    <?php
    if (isset($_GET['image']))
    {
    $fh = fopen("choices.inc", 'a') or die("can't open file");
    
    fwrite($fh, '<?php $images[] = '."'".$_GET['image']."'; ?>\n");
    
    fclose($fh);
    echo "Thank you for your selection";
    }
    else echo "Something funny happened, no data saved :)";
    ?>
    </p></body></html>
    Save it, then create a new file called viewresults.php
    In it, put this:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    
    <html><head>
    <title>Results Page</title>
    </head><body>
    <?php
    $images = array();
    if (isset($_GET['code']))
    	{
    	if ($_GET['code'] == 'yoursecretpassword')
    		{
    		if (file_exists("choices.inc"))
    			{
    			require_once("choices.inc");
    			}
    		else echo "file not found! Any data saved?";
    		}
    	}
    
    $results = array_count_values($images);
    ksort($results,SORT_NUMERIC);
    
    echo "<table border='1'><tr><th>Image<th>Times Selected";
    foreach ($results as $key => $value)
    	{
    	echo "<tr><td>$key<td>$value";
    	}
    
    echo "</table>";
    ?>
    </body></html>
    And save it. You're all done!

    Now whenever you want to view the results, go to
    http://yoursite.com/youdirectory/viewresults.php?code=yoursecretpassword
    You will see the results in a table, with everything totalled up.

    You should change the password, as well as the original HTML page with different values for the images in both the links and the actual image tags, and then you should find it works perfectly ;)
    (btw, it's untested, but should work)
    Last edited by Scoochi2; 09-09-2008 at 05:28 PM. Reason: results page now has an order :)
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  3. #3
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Red face Re: transferring dynamic data

    sounds unreal! Just getting a parse error at the moment:

    Parse error: syntax error, unexpected T_STRING in /home/bungle/public_html/MFPOI/viewresults.php on line 11


    Line 11 is this:

    PHP Code:
    require_once("choices.inc") or die("file not found!" Any data saved?"); 

  4. #4
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: transferring dynamic data

    Quote Originally Posted by bunglebrown View Post
    PHP Code:
    require_once("choices.inc") or die("file not found!" Any data saved?"); 
    Wh00ps!
    Change it to this:
    PHP Code:
    require_once("choices.inc") or die("file not found! Any data saved?"); 

    EDIT: I suppose just in case you haven't figured it out... if you want to reset everything to zero, just delete the file choices.inc
    You can also edit that page in the file manager to change the results as you so wish.

    If you really want it emailed to you, you can also set up the cron daemon to email you the results every week and then reset it (or however often you wish).
    If you want that and need help, ask
    Last edited by Scoochi2; 09-09-2008 at 04:03 PM. Reason: extra info
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  5. #5
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Re: transferring dynamic data

    Again thanks - I guess I should have spotted that.. unfortunately that isn't quite where it ends happily. . .another parse error came back:

    Parse error: syntax error, unexpected T_FOREACH, expecting ',' or ';' in /home/bungle/public_html/MFPOI/viewresults.php on line 16


    Line 16:
    PHP Code:
    foreach ($results as $key => $value
    Might be obvious but not to me.

  6. #6
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: transferring dynamic data

    Just found another error in that last page.
    On line 15, add a semicolon onto the end so it becomes this:
    PHP Code:
    echo "<table><tr><th>Image<th>Times Selected"
    EDIT: Ha! I didn't even see your post before I posted this.
    Anyway, for that last file I have edited my first post. Copy paste the edited version into your file.
    I have checked in on my server and it works 100%.
    In addition to those few bug fixes, I have also ordered the results, so rather than having a bit of everything anywhere, they now make sense when you're looking for a particular one
    Last edited by Scoochi2; 09-09-2008 at 05:30 PM. Reason: update in first post
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  7. #7
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Re: transferring dynamic data

    ok added and yes i should have seen it again. I think sometimes that maybe you are testing me.. ..

    Am i right in thinking that by going straight to the viewresults.php page I should be able to see the results because there is only "ImageTimes Selected" displayed and no data - it seems something isn't registering and I know you've tested it. But do you think that there are any variables I should be changing apart from the images.

    I hope you realise my appreciation on this one.

  8. #8
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: transferring dynamic data

    did you make sure that the address you visit has ?code=12345whatever on the end?
    (where 12345whatever is the secret password from the code on the last page)

    If so, then yes you should see the results.
    If there is no data, that might be because nobody has clicked on the link yet ;)
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  9. #9
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Re: transferring dynamic data

    yes I'm now doing that and getting:

    Warning: require_once(1) [function.require-once]: failed to open stream: No such file or directory in /home/bungle/public_html/MFPOI/viewresults.php on line 11

    Fatal error: require_once() [function.require]: Failed opening required '1' (include_path='.:/x10hosting/php2/pear/PEAR') in /home/bungle/public_html/MFPOI/viewresults.php on line 11
    Not sure why. What else am I doing wrong??

    Edit:
    I've put up this test page to show in greater detail what I am trying to achieve:

    Test Page (currently not available in IE for some idiotic reason)

    I want the image ID to be sent to the 2nd slide in the middle section so the user (and later I) can identify which image was selected.

    Also as you can see the yellow square changes when you scroll off the image after clicking - I would like it to stay selected (yellow).

    All comments welcome!
    Last edited by bunglebrown; 09-11-2008 at 09:41 AM. Reason: Automerged Doublepost

+ Reply to Thread

Similar Threads

  1. Dynamic images with PHP
    By marshian in forum Tutorials
    Replies: 24
    Last Post: 10-30-2008, 11:14 AM
  2. Creating a dynamic data area
    By stalkio in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 08-25-2008, 10:45 AM
  3. 9000+ websites down due to explosion at H1 data center
    By jonathanyaniv in forum Off Topic
    Replies: 15
    Last Post: 06-01-2008, 08:19 PM
  4. HTML help...
    By anuj_web in forum Programming Help
    Replies: 5
    Last Post: 05-08-2008, 11:22 AM
  5. [PHP] Dynamic Includes Tutorial
    By Bryon in forum Tutorials
    Replies: 3
    Last Post: 12-16-2005, 01:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers