Trouble with a select list


Posted on 16th Feb 2014 07:03 pm by admin

Hello All!
I was wondering if any of you guys could help me with a small problem I'm having!

I'm trying to add a select list to a form on my webpage.

The select list is generated from information stored in a database.

The table has 25 rows in it presently and what I'm trying to do is list only one column of the rows to create a select list.

An example of this:

Populating a select list with all of the names in a member database.

Here is the relevant code:




$ReqQry=" SELECT `traitname` FROM `traitslist` ";
$ReqResult= mysqli_query($cxn , $ReqQry)or die('Ya did it wrong');
$TraitInfo= mysqli_fetch_assoc($ReqResult);
$TraitCnt= mysqli_num_rows($ReqResult);



$list1=$TraitCnt;

echo "Required Skill 1-"."</br>";
echo "<select id='Req1'>";

foreach($TraitInfo as $v)
{
while($list1 > 0)
{
echo "<option value='$v'>$v</option>";
$list1--;
}


}
echo "</select>"."</br></br>";




The problem that I am having is that the select list generates the same entry 25 times.

Any help would be appreciated, as I have fiddled around with it for about two days in my off-time and no luck yet. Thanks
*ps* I'm still rather wet behind the ears with PhP so be gentle

No comments posted yet

Your Answer:

Login to answer
300 Like 52 Dislike
Previous forums Next forums
Other forums

Creating a custom API
I'm creating a site, and I need to create a basic API. Unfortunately I have no idea where to start.

setcookie and isset($_COOKIE(name)) seem very finnicky.
I'm currently playing around with a user system with login and registration. I'm trying to use cooki

Inter Company -- Resources Related Billing (Services Industry)
Hello,

My company has a scenario where:
Company A bills Company C for INTER (cross

Packet Design
Hi All,
Im new about network programming and I want to design a protocol but I have some question

subtract 1 from value entered in text field
Hi

How do I subtract 1 from the vaue entered into a text field?

Thanks

Adding Outlook 2007 items via file upload
I am looking for a way to be able to attach an Outlook item (an email message) in an ASP.NET 3.5 app

duplicate record notification
In my database, after insertion of records, I want to know if the record inserted is duplicate or no

Restricted access to sub-folder in iis6 doesn't work?
Basically I'm trying to add restriction to sub-folder (which contains pdf) in web.config for iis6 as

Appending GET data with form submition
Okay, what I'm trying to do is to use a form to append an already existing GET data string.

I

Get dump of MySQL DB from Live Site
I'm after an easy, but secure way of generating and importing a MySQL dump from a remote server.

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash