Aysha Azura
Aysha Azura

Reputation: 179

Listing out details from database

i am developing a website for meeting schedule.the user which was currently logged in need to send request to the guests.the names of the guests are provided in the user table in database along with the host.so when i try to fetch the names of all the user expect that of the host only the host's name is displayed in the list menu.my code is as follows

<?php
include("db.php");
$q=mysql_query("select * from user where name='$name'");
while($r=mysql_fetch_array($q))

{ $uid=$r['uid'];

?>

<select name="">
<option name="">geust name</option>
<?php
echo'<option name="">'.$name.'</option>';
?>
</select>
<?php
}?>

i want to list out the guest names in the option other than that of the host.but i dont know how to display it

Upvotes: 0

Views: 33

Answers (2)

bart2puck
bart2puck

Reputation: 2522

In your above example you are creating a new select element each Time you loop through results. you are using $name as option value. $name is the value of your search criteria. You want to use $r['name']. Witherwind's answer will get you what you asked. The only thing you need to change is the first option outside loop should be blank.

Upvotes: 0

witherwind
witherwind

Reputation: 472

Try this:

<?php
   include("db.php");
   $q=mysql_query("select * from user where name='$name'");
?>

<select name="sample">
    <option value="<?php echo $r['guestname']; ?>">geust name</option>
    <?php
       while($r=mysql_fetch_array($q))
    ?>
          <option value="<?php echo $r['name']; ?>"><?php echo $name; ?></option>;
    <?php
       }
    ?>
</select>

Upvotes: 2

Related Questions