Page 2 of 3

Everah

Posted: Sun Aug 20, 2006 1:35 pm
by akimm
i probablymanaged to mess something up, but it says i've supplied an improper argument for the foreach, isthere anything thatcould of caused this?

Code: Select all

<?php
$smiles = array('2guns', '<span style='color:blue' title='I&#39;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 />';
}
?>

Posted: Sun Aug 20, 2006 2:11 pm
by daedalus__
$smiles != $smile;

Ah...

Posted: Sun Aug 20, 2006 3:59 pm
by akimm
Thank you very much, that makes a lot of sense, I missed that a few times over.

Posted: Sun Aug 20, 2006 5:36 pm
by RobertGonzalez
Daedalus- wrote:$smiles != $smile;
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 :oops: . 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.

Posted: Sun Aug 20, 2006 5:55 pm
by griffinmt
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.

problems still

Posted: Sun Aug 20, 2006 6:37 pm
by akimm
The code is processed, but still the images are not working.

Code: Select all

<?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 />';
}
?>

yea

Posted: Sun Aug 20, 2006 6:40 pm
by akimm
I knew != was inequality.
it still doesn't work

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?

Posted: Sun Aug 20, 2006 6:49 pm
by jayshields
Your closing select tag is missing a forward slash.

Ok

Posted: Sun Aug 20, 2006 7:30 pm
by akimm
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.

Posted: Sun Aug 20, 2006 10:52 pm
by RobertGonzalez
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.

html output

Posted: Mon Aug 21, 2006 1:13 am
by akimm
feyd | Please use

Code: Select all

,

Code: Select all

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]


[syntax="html"]
<form action="journalbox.php" method="POST">
<p><b>Date</b>
<input type="text" value="August 20, 2006, 8:42 pm" name="date" size="30"></p>

<p><b>Mood</b>
<select name="mood">
<option value="apathetic">apathetic
<option value="overjoyed">overjoyed
<option value="inquisitive">inquisitive
<option value="outlandish">outlandish
<option value="appreciative">appreciative
<option value="confused">confused
<option value="displeased">displeased
<option value="disgruntled">disgruntled
<option value="sick">sick
<option value="terrified">terrified
<option value="mental">mental
<option value="eruditic">eruditic
<option value="forlorn">forlorn
<option value="convuluted">convuluted
<option value="ingenious">ingenious
<option value="arrogant">arrogant
<option value="free">free
<option value="stupid">stupid
<option value="moronic">moronic
<option value="pointless">pointless
</select>

<select name="smiles">
<select name="smile"><option value="0">2guns</option><img src="/journal06/smile/2guns.gif" /><br /><br /><option value="1">somethingElse</option><img src="/journal06/smile/somethingElse.gif" /><br /><br /></select>

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

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]

Posted: Mon Aug 21, 2006 8:30 am
by RobertGonzalez
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:

Code: Select all

<?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:

Code: Select all

<?php
$img_id = $_POST['smile'];
echo '<img src="/path/to/images/' . $smile[$img_id] . '.jpg" />';
?>

ok

Posted: Mon Aug 21, 2006 11:05 am
by akimm
Thank you for clarifying that. I appreciate the help you've provided, I am going to test this code.

Well

Posted: Mon Aug 21, 2006 11:20 am
by akimm
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.

Posted: Tue Aug 22, 2006 12:22 am
by RobertGonzalez
Post what you have. Let's have a look at it.