/    Sign up×
Community /Pin to ProfileBookmark

Creating a select menu in a script

Hello:

I have a script which allows me to edit information and update the database. Right now, the script creates grabs everyone in the table and has a link to edit that person.

Instead, I would like to incorporate a select menu so instead of seeing everyone in the table, the person can select the person they want.

Can anyone point me in the right direction as to how I can modify that portion of the script to include a select menu?

This is the portion of the script that grabs everyone from the table:

[code=php]
if(!isset($choice))
{
//display all the customers
$result = mysql_query(“select * from customer order by id”);

//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$fname=$r[“fname”];
$lname=$r[“lname”];
$id=$r[“id”];

$fullname = $fname . ” ” . $lname;

//make the title a link
echo “$fullname <a href=’edit.php?choice=edit&id=$id’>Edit</a>”;
echo “<br>”;
}
}
?>
[code=php]

The line that actually displays the names with the edit link is the following:

echo “$fullname <a href=’edit.php?choice=edit&id=$id’>Edit</a>”;

Instead of the above line, I would like it to be a select menu.

I hope someone can help.

Thank you.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@mattyblahSep 07.2004 — [code=php]
if(!isset($choice))
{
//display all the customers
$result = mysql_query("select * from customer order by id");

//run the while loop that grabs all the news scripts
echo '<select name="sname">';
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$fname=$r["fname"];
$lname=$r["lname"];
$id=$r["id"];

$fullname = $fname . " " . $lname;

//make the title a link
echo "<option value="$fullname">$fullname</option>";
}
echo '</select>';
}
?>
[/code]


You also need a javascript to redirect to the appropriate edit page, but this code should work to make the pull-down menu.
×

Success!

Help @summit310 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...