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>

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

Wrap your codes with CODE tag.

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.

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

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.