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

smart reading from a text file
Hello there fellow coders, i was wondering if one of you wouldnt mind helping me with this problem i

PEAR Email Attachment w/ $gpg
I have no issues with this code if I take out the attachement section and include the info in the em

Problem with HTTP Caching...?
Hi there, im trying to implement caching. But it doesn't always work.
I post it here because ther

Show specific day of the week
I have been racking my brain trying to get this function to work properly and it is doing so for eve

remove trailing slash from array
I have the following array which contains trailing slashes I need to remove. What is the best way to

path to include folder
Hi everyone,

When I'm testing locally, I have to add the name of the site folder as part of t

form problem
below in the form action, i've put "test.php?w=$sw&h=$sh" but when i input the for

help me, how to find text on an external html site using PHP
Would anyone know how to search an external html file for a work or phrase ?

I was thinking s

disabling a button server-side then re-enabling client-side breaks button postback
I have a tabbed container and a button (not in the container) on a page. If the first tab is selecte

Passing an array of values From VB6.0 to Oracle PL/SQL Function
Basically we are using VB6.0.

When we try to pass an array from VB6.0 to an Oracle PL/SQL

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