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
acwe88
Forum Newbie
Posts: 24 Joined: Tue Nov 07, 2006 10:47 am
Post
by acwe88 » Mon Nov 27, 2006 7:15 am
feyd | Please use 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]
Hi there,
i have a mysql database table called dictionary.
the fields in this table are letter, word and description
what i need is when a user selects for example Alex (in the field "word") the text in the description field is displayed?
This code displays a select form which gets all the "A" values from the field "letter" in my databaseCode: Select all
$sql = 'SELECT word FROM dictionary WHERE letter="A"';
$res = mysql_query($sql) or die(mysql_error());
while ($rec = mysql_fetch_assoc($res)) $word[] = $rec;
echo '<SELECT name="dropdown">';
foreach ($word as $c)
echo "<OPTION>{$c['word']}</OPTION>\n";
echo '</SELECT>';
Any help will be much appreciated
Thanks
Alex
feyd | Please use 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]
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Mon Nov 27, 2006 8:07 am
I think this is what you are trying to do:
Code: Select all
$sql = "SELECT word FROM dictionary WHERE letter LIKE 'A%'";
acwe88
Forum Newbie
Posts: 24 Joined: Tue Nov 07, 2006 10:47 am
Post
by acwe88 » Mon Nov 27, 2006 9:45 am
thanks
So how would i display the description result when a user selects a value from the select box
so basically if i select alex from the drop down box i need a peice of text to appear below which shows the description
Thanks
Al
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Mon Nov 27, 2006 9:49 am
Do you plan on using AJAX or reloading the page?
acwe88
Forum Newbie
Posts: 24 Joined: Tue Nov 07, 2006 10:47 am
Post
by acwe88 » Mon Nov 27, 2006 9:59 am
Not sure really ive had a little look at ajax and still dont know what to do
id like it to automatically dispay the result but not to sure if i can even do this
Thank
Al
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Mon Nov 27, 2006 10:09 am
If you are a noob, I'd recommend refreshing the page first and then try to do it using AJAX. To display the description:
Option (a) Create an onChange event in the select box (b) Add a button to submit the form
Reload the page but with a GET parameter with the value of the selected item.
When the page is loaded check for that GET parameter. If it is there display the info. If not do not display any info...
This should be enough info to get you started...
acwe88
Forum Newbie
Posts: 24 Joined: Tue Nov 07, 2006 10:47 am
Post
by acwe88 » Mon Nov 27, 2006 11:46 am
hi cant i do something like this
if the word is on the same row as the description display that description
so then on my <select> part i could put onchange=\"get_description()\"
Does this make sense and if you could post how i would do this i would appreciate it very much
Thanks
AL
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Mon Nov 27, 2006 12:30 pm
Try something like this:
Code: Select all
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="get" name="form1">
<select name="sel_test" onChange="this.form.submit();">
<option value="Alex">Alex</option>
<option value="Alex 2">Alex 2</option>
</select>
</form>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Nov 27, 2006 2:09 pm
*cough* XSS attack.
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Mon Nov 27, 2006 2:22 pm
feyd wrote: *cough* XSS attack.
The point was to give an example...no guarantees
aaronhall
DevNet Resident
Posts: 1040 Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:
Post
by aaronhall » Mon Nov 27, 2006 8:16 pm
Code: Select all
<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>
Always sanitize PHP_SELF