0

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>'; 


?>
3
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by braveheart_sb
0
<?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>'; 
?>
0

<?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();
?>

0

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>'; 
?>
0

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 ?

0

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.

0

Line 7:

echo '<option value="' . $row['curso_name'] . '-' . $row['curso_periodo'] .'">' . $row['curso_name'] . '-' . $row['curso_periodo'] . '</option>';
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.