combo box and string

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

Post Reply
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

combo box and string

Post by hrubos »

hi all,

I have 2 fields first_name, last_name and I want to output both of fhem into combo box. I have done but i doesn't work exactly

and I want it outputted with newline.

Code: Select all

<?php
$query = "SELECT last_name,first_name 
            FROM student
        ORDER BY first_name ";

$search_stu=mysql_query($query)or die(mysql_error());
//creat array for last name
$name = array();

//last name into array
while ($row = mysql_fetch_assoc($search_stu))
{
array_push($name, $row["last_name"]);
array_push($name, $row["first_name"]);
}
?>
<select name="name">
<? foreach($name as $value) { ?>
<option value="<?= $value ?>"><?= $value ?></option>
<? } ?>
</select>
</td>
<?= $line["name"] ?>

</td><tr>
</table>
Thank in advance
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Can you explain what "I want it outputted with newline?"
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post by hrubos »

if follow my code, it was ouputted by typ combo box but the first line in combo box was a element and was selected. But I want that the first line is free.

So how should I do ???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

To make the first option (the default selection) empty, you must provide an empty option.
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post by hrubos »

Thanks , I got it.

But I have more important problem that I want to output both of last name and first name in a row beacause I have 2 different fields , last_name and first_name.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

hrubos wrote:Thanks , I got it.

But I have more important problem that I want to output both of last name and first name in a row beacause I have 2 different fields , last_name and first_name.

Code: Select all

while ($row = mysql_fetch_assoc($search_stu))
{
  array_push($name, $row["last_name"] . ', '.$row["first_name"]));
}
Post Reply