0

value is not showing in the combo box

<?

$cn=mysql_connect("localhost","root");
mysql_select_db("test",$cn);

// Make a MySQL Connection
// Construct our join query
$query = "SELECT one.name,two.address FROM one,two where one.name=two.name";

$result = mysql_query($query) or die(mysql_error());



echo " name "."address";
echo "<br />";   
while ($row=mysql_fetch_array($result)){



    echo $row['name']. " - ".$row['address'];

echo "<br />";

}   

?>



<select name="patient_id_2" id="patient_id_2">
<?
    while($res1=mysql_fetch_assoc($result))
    {
    ?>
    <option value="<? echo $res['name'] ?>">
    <?
    echo $res['name']
    ?>
    </option>
    <?
    }
    ?>
    </select>

Edited by Nick Evan: Fixed formatting

5
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by Rhamises
0

you are using $res1 in your while statement and only $res[] in your echo statements.
change them to all be $res1 or $res.

0

The way mysql_fetch_array() works is that it sets a pointer which knows which row you're going for.

After your while($row...) statement is completed you have to reset this. You can do this with:

<?php
mysql_data_seek($result,0);
?>

The technical documentation for this function is available here.

Your second problem is what ddymacek mentioned:

you are using $res1 in your while statement and only $res[] in your echo statements.
change them to all be $res1 or $res.

0

i have encountered some stuffs like new version of xampp doesn't read

<? as opening of php code . it reads as <?php
then another thing your echos don't end at " ; "

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.