On Sun, Feb 02, 2003 at 04:55:08PM -0500, Matt wrote:
>
> > i have a listbox:
> > <select name="users">
> > <?php
> > //connect to db and get query
> > mysql_connect(".....");
> > mysql_select_db("...");
> > $query=mysql_query("select username from users);
> > /*finish the listbox*/
> > while($account=mysql_fetch_array($query)){
> > echo "<option value=$account[username]>$account[username]<br>";
>
> Try:
> echo "<option value={$account['username']}";
> $selected = ($account['username'] == $_POST['user']) ? 'selected' : '';
> echo $selected;
> echo ">{$account['username']}<br>";
>
> > }
> > ?>
> > </select>
> > <input type="submit" value="send">
This is good. I've always liked things like this:
$query="SELECT ...";
if ($result=mysql_query($q)) {
$sel[$user]=" selected";
print "<select name='users'>\n";
while ($row=mysql_fetch_array($result)) {
printf(" <option value='%s'%s>%s</option>\n", $row['id'], $sel[$row['id']],
$row['text']);
}
print "</select>\n";
}
--
Paul Chvostek <[EMAIL PROTECTED]>
Operations / Abuse / Whatever
it.canada, hosting and development http://www.it.ca/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php