Page 1 of 1

combo box and string

Posted: Tue Feb 27, 2007 7:35 am
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

Posted: Tue Feb 27, 2007 9:30 am
by feyd
Can you explain what "I want it outputted with newline?"

Posted: Tue Feb 27, 2007 10:12 am
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 ???

Posted: Tue Feb 27, 2007 10:28 am
by feyd
To make the first option (the default selection) empty, you must provide an empty option.

Posted: Tue Feb 27, 2007 10:41 am
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.

Posted: Tue Feb 27, 2007 1:09 pm
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"]));
}