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!
<?php
$smiles = array('2guns', '<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span>');
/**
* This generates a drop down with
* the array index as the key and
* the smilie name as the value in the form
**/
echo '<select name="smile">';
foreach ($smile as $key => $value)
{
echo '<option value="' . $key . '">' . $value . '</option>';
}
echo '<select>';
/**
* This makes a list of all images displayed
**/
foreach ($smile as $key => $value)
{
echo '<img src="/journal06/smile/' . $value . '.gif" /><br /><br />';
}
?>
Translating from geek to English, this means that the var name $smiles is not the same as the var name $smile.
EDIT | Ok, sorry for the bad code . I didn't see it until I went back and looked at it that I did that to you. I apologize for that. The argument supplied to the foreach construct should be the var name of the array that you want to loop. Sorry for the mistake.
Several posts up, it was mentioned that the content of the option value attribute can't be a tag.
In fact, it can be anything located between the quotes, including a tagged structure. BUT, it is treated as just text and passed with the post or get data as such.
In order to make that work, you will have to correctly 'balance' your use of double and single quotes.
<?php
$smile = array('2guns', 'somethingElse');
/**
* This generates a drop down with
* the array index as the key and
* the smilie name as the value in the form
**/
echo '<select name="smile">';
foreach ($smile as $key => $value)
{
echo '<option value="' . $key . '">' . $value . '</option>';
}
echo '<select>';
/**
* This makes a list of all images displayed
**/
foreach ($smile as $key => $value)
{
echo '<img src="/journal06/smile/' . $value . '.gif" /><br /><br />';
}
?>
It won't print the smiles, i just used two to see if perhaps two would work before i typed all 92 names. Is there an error i made or an error in the code?
I fixed the mistake, but the code doesn't work as suggested, I keep trying to tweak little things, but nothing so far has made the images appear in the select menu, i will continue tweaking crap, if you have any idea why this might be i'm open to all suggestions.
After you load the page and it doesn't do what you want, do a view source to see the output HTML. Post the HTML that is generated from that code so we can that.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
The HTML is wonky. Take the part about displaying the image out. That was for reference.
Logically, what you want, is a list that allows the users to see what images they want to insert. Then the user selects that image and it gets inserted. If you are trying to do this the way these forums do it, then we are in the wrong track. If you want to do where a text value is chosen from a list and then, after the form is submitted, the image shows, then on the form, run the following code:
<?php
$smile = array('2guns', 'somethingElse');
/**
* This generates a drop down with
* the array index as the key and
* the smilie name as the value in the form
**/
echo '<select name="smile">';
foreach ($smile as $key => $value)
{
echo '<option value="' . $key . '">' . $value . '</option>';
}
echo '<select>';
?>
And after it is posted, use the passed value to show the image:
Everah, it still doesn't work. I don't understand why, your code seems to haveeverything as it should be. aside from the few constants i had to change it should be working. My goal is for me since this is a journal for me only to select a word like '2guns' and it will pass this value on when it goes into the textfile, then when reprinted as html it will know it wants 2guns.gif in this space.