Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mrfruits
Forum Newbie
Posts: 5
Joined: Wed Feb 27, 2008 9:53 pm

Help

Post by mrfruits »

I have this code

Code: Select all

<?
//var to hold list location (substitute your own file name and text file)
$your_file = "photolink.txt";
 
        //open the file
        $read_your_file = @fopen($your_file, "r") or die ("Couldn't Access $your_file");
 
        //create a variable to hold the contents of the file
        $contents_your_file = fread($read_your_file, filesize($your_file));
        
        //array of file contents
        $your_array = explode("\n",$contents_your_file);
 
        //close the file
        fclose($read_your_file);
 
        //counts the number elements in the property_categories array
        $num_elmnts_array = count($your_array) ;
 
//elements in the drop down list
//$drop_elmnts = 0;
 
//begin creating your dropdown menu...
$your_menu = "<select name=\"you_make_a_name\">";        
        //For loop to begin
        for($counter = 0; $counter < $num_elmnts_array; $counter++){
         $your_menu .= "<option value=\"$your_variable\">$your_array[$counter]
</option>";
                $counter++;
        }
//end select menu
$your_menu .= "</select>";
 
?>
<html>
<head>
<title>Edit Photos</title>
</head>
<body>
<p><b>Photos</b><br>
<? echo "$your_menu"; ?>
 
</body>
</html>

And what I have in the text file are lines of urls to photos, ie http://www.website.com/pic.jpg, and what I am trying to figure out is how to get the photo I have selected in the drop list to display. any help would be great.
User avatar
hawkenterprises
Forum Commoner
Posts: 54
Joined: Thu Feb 28, 2008 9:56 pm
Location: gresham,oregon
Contact:

Re: Help

Post by hawkenterprises »

Code: Select all

$your_menu = "<select name=\"you_make_a_name\" onselect="displayphoto(this.selectedItem[selectedIndex])">";

Code: Select all

 
<script type="text/javascript">
function displayphoto(imagename){
         document.getElementById("displaybox").innerhtml = "<img src='"+imagename+"'>";
}
</script>
<div id="displaybox"></div>
 
I just typed this up really quick and didn't test it but I think it will illustrate the idea and how to make it AJAXY. Basically you use javascript to make the selection work, I think my code in the onselct is wrong but it's close check w3schools.com for it, the rest should be straight.
mrfruits
Forum Newbie
Posts: 5
Joined: Wed Feb 27, 2008 9:53 pm

Re: Help

Post by mrfruits »

I am new to PHP and basicly no nothing. They example they use is

Code: Select all

<form>
 
Select text: <input type="text" value="Hello world!"
onselect="alert('You have selected some of the text.')">
<br /><br />
Select text: <textarea cols="20" rows="5"
onselect="alert('You have selected some of the text.')">
Hello world!</textarea>
 
</form>


but that is a built in function i guess. And you are making a new one? not sure how it all works but it seems like you are using it correctly but it doesnt work. I get this error
(Parse error: syntax error, unexpected T_STRING in /home/dp411net/public_html/phphotos/getlist.php)
That error happens right were I add your new code to my code. Sorry for being so noobish.
User avatar
hawkenterprises
Forum Commoner
Posts: 54
Joined: Thu Feb 28, 2008 9:56 pm
Location: gresham,oregon
Contact:

Re: Help

Post by hawkenterprises »

Try this link it might help you out.
http://www.cross-browser.com/toys/img_gallery_2.php
Post Reply