Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add item to option list (MYSQL backend)

Status
Not open for further replies.

hpicken

Technical User
Apr 12, 2001
142
AU
Ok...

I've got a few pages for which I've used a function to fill an option list with MYSQL DB values as below.

function SectionListBox()
{
$result3=mysql_query("SELECT DISTINCT section FROM htg ORDER BY section");

echo &quot;<select name=\&quot;section\&quot;><br>&quot;;
echo &quot;<option value=>Select a section ...&quot;;

while ($row3 = mysql_fetch_array($result3))
{
$section = $row3[&quot;section&quot;];
echo &quot;<option value='$section'>$section</option>&quot;;
}
echo &quot;</select>&quot;;
}

In the form I simply add the following...

Section:<?php sectionlistbox() ?>

etc...

What I'd like to do is allow for an item that is not on the list.

This might be a bit off list but I think that I'll have have use PHP to get what I want.

Howard
 

$add_opt=&quot;additional option&quot;;


function SectionListBox()
{
$result3=mysql_query(&quot;SELECT DISTINCT section FROM htg ORDER BY section&quot;);

echo &quot;<select name=\&quot;section\&quot;><br>&quot;;
echo &quot;<option value=>Select a section ...&quot;;

while ($row3 = mysql_fetch_array($result3))
{
$section = $row3[&quot;section&quot;];
echo &quot;<option value='$section'>$section</option>&quot;;
}

if (isset($add_opt)){
echo &quot;<option value='$add_opt'>$add_opt</option>&quot;;
}

echo &quot;</select>&quot;;
} ***************************************
Party on, dudes!
[cannon]
 
Woops .. the $add_opt=&quot;blah&quot;; needs to be set inside the function. ***************************************
Party on, dudes!
[cannon]
 
OK That's alright if I know what the option is but
what if the option is not on the list and I want
to allow the &quot;adder&quot; to add their own.

Bassically I'm trying to save people time by selecting
things from the list but not use a selection from the
list if neccessary. (if that makes sense)

H
 
You should make a text field where they can add there option if it is not on the list.
you can not add an option in the list itself.

I made this for my whiskysite, if not in list put it in below. after submit and reload it is in the selection list (if you have inserted the new option)

$query=&quot;SELECT distinct(whname) FROM whiskytable order by whname&quot;;
$rs=mysql_query($query,$conn);

<tr><td><p>Whisky</P></TD><td><select name=&quot;whname&quot;><option value=&quot;&quot;>Empty
<?
$list = mysql_num_rows($rs);
while($i < $list) {
$row = mysql_fetch_array($rs);
$whname=$row[&quot;whname&quot;];
echo &quot;<option value='$whname'>$whname&quot;;
$i++;
}
?>
</select></TD><td></td></TR>
<tr><td>If whisky not in list</td><td><INPUT TYPE=&quot;text&quot; name=whname1 size=50></td><td></td></tr>

kind regards
 
like hos2 says, add a textfield and name it add_opt then it should go into the list ok. ***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top