/    Sign up×
Community /Pin to ProfileBookmark

about dropdown box

Hi ,
I created code for showing name using dropdown box inthat dropdown box all names are stored directly from the database.here i send the code also but its not working can anyone tell why its not working

Thanks
Punithapary

Code:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head>

<body>
<form>
<table align=”center”>
<tr>
<td>Select any name</td>
<td>
<select name=”select” style=”width: 150px”>
<?php

$catagory_sql = “SELECT * FROM `register` ORDER BY `fname` ASC”;
$enr=mysql_query($catagory_sql);
echo $cnr = mysql_num_rows($enr);
if($cnr > 0)
{
while($ca1 =mysql_fetch_array($enr))
{
echo ‘<option value=”‘ . $ca1[id] . ‘”>’ . ucwords(“$ca1[fname]”) . ‘</option>’;

$catagory_psql=”SELECT * FROM `register` WHERE `id` = $ca1[id] ORDER BY `fname` ASC”;
$enrp = mysql_query($catagory_psql);
$cnrp = mysql_num_rows($enrp);
if($cnrp > 0)
{
while($ca1p =mysql_fetch_array($enrp))
{
echo ‘<option value=”‘ . $ca1p[id] . ‘”>—‘ . ucwords(“$ca1p[fname]”) . ‘</option>’;
}
}
}

}
?> </select> </td>
<input type=”submit” name=”submit” value=”submit” />

</tr>
</table>
</form>
</body>
</html>

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ZnupiJul 16.2008 — Try this bit of niceified code:
[code=php]
<?php

$catagory_sql = "SELECT * FROM register ORDER BY fname ASC";
$enr = mysql_query($catagory_sql);
echo $cnr = mysql_num_rows($enr);
if($cnr > 0) {
while($ca1 = mysql_fetch_array($enr)) {
echo '<option value="' . $ca1['id'] . '">' . ucwords($ca1['fname']) . '</option>';

$catagory_psql = "SELECT * FROM register WHERE id = {$ca1['id']} ORDER BY fname ASC";
$enrp = mysql_query($catagory_psql);
$cnrp = mysql_num_rows($enrp);
if($cnrp > 0) {
while($ca1p = mysql_fetch_array($enrp)) {
echo '<option value="' . $ca1p['id'] . '">---' . ucwords($ca1p['fname']) . '</option>';
}
}
}
}

?>
[/code]

Also, I don't quite see what you're trying to do. To me it looks like that piece of code is identical in functionality to:
[code=php]
<?php

$catagory_sql = "SELECT * FROM register ORDER BY fname ASC";
$enr = mysql_query($catagory_sql);
echo $cnr = mysql_num_rows($enr);
if($cnr > 0) {
while($ca1 = mysql_fetch_array($enr)) {
echo '<option value="' . $ca1['id'] . '">' . ucwords($ca1['fname']) . '</option>';
echo '<option value="' . $ca1['id'] . '">---' . ucwords($ca1['fname']) . '</option>';
}
}

?>
[/code]

?
×

Success!

Help @punithapary 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.12,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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