Hi,
I'm Having a Problem with populating a combo box with more than one result from a query.
until this stage i have managed to get the first Row Curso_name,but i still find difficulty in displaying the second row and also adding a "-"between both the rows.

Thank You!

<?php 

include("connection.php");

$sql ="SELECT curso_name,curso_periodo FROM curso";

$query = mysql_query($sql);


echo '<select name="primeira_opcao">';
while ($row = mysql_fetch_array($query)) {
while ($row = mysql_fetch_array($query)) {
echo '<option value="',$row['curso_name'],'">',$row['curso_name'],'</option>';
}
echo '</select>'; 


?>
<?php 
include("connection.php");
$sql ="SELECT curso_name,curso_periodo FROM curso";
$query = mysql_query($sql);
echo '<select name="primeira_opcao">';
while ($row = mysql_fetch_array($query)) {
  echo '<option value="' . $row['curso_name'] . '">' . $row['curso_name'] . '</option>';
}
echo '</select>'; 
?>

<?PHP
include("connection.php");
$result=mysql_query("SELECT curso_name,curso_periodo FROM curso");
?>
<select name="primeira_opcao">
<?PHP
while($rows=mysql_fetch_array($result))
{?>
<option value="<?PHP echo $row?>"><?PHP echo $row?></option>
<?PHP
}
?>
</select>
<?PHP
mysql_free_result($result);
mysql_close();
?>

Thank you for your replies i learned something with them.
I decided to follow my own way towards solving this problem i believe the 2steps are solved.

The third issue is that i need to insert a "--" in the comboBox Between this 2 rows.

$row['curso_name'] . '""' . $row['curso_periodo']

The entire code goes Below already populating 2 rows from the database!
Thank you.

<?PHP
include("connection.php");
$sql ="SELECT curso_name,curso_periodo FROM curso";
$query = mysql_query($sql);
echo '<select name="primeira_opcao">';
while ($row = mysql_fetch_array($query)) {
  echo '<option value="' . $row['curso_name'] . '""' . $row['curso_periodo'] .'">' . $row['curso_name'] . '' . $row['curso_periodo'] . '</option>';
}
echo '</select>'; 
?>

You could add an empty option for that after the first one, but what if you have three or more ? What do you want to happen then ?

You could add an empty option for that after the first one, but what if you have three or more ? What do you want to happen then ?

I didn't understood you ,but what i intend is simple the display on the combo box to contain field1-field2.
At the moment im displaying field1field2 what im in need is the separator "-".
As you know im populating both fields from the database.

Line 7:

echo '<option value="' . $row['curso_name'] . '-' . $row['curso_periodo'] .'">' . $row['curso_name'] . '-' . $row['curso_periodo'] . '</option>';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.