•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 427,322 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,928 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 4326 | Replies: 2
![]() |
•
•
Join Date: Jul 2006
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
Dear all
I want to populate a few drop down boxes using PHP. However i have tried many examples i found from the web but the select box does not get any values. Below i have one example i have tried.
**********************************************
<?php
$link = mysql_connect("localhost", "root", "password") or die("Could not connect: " . mysql_error());
mysql_select_db('db', $link) or die (mysql_error());
$query = "SELECT last_name FROM main_author order by last_name";
$result = mysql_query($query) or die("Couldnt' execute query.");
$num = mysql_numrows($result);
?>
<html>
<body>
<form name="test" id="test" method="post">
<select value="" size="1" name="test2">
<option>all</option>
<? $i=0; while ($i<$num)
{$authors=mysql_result($result,$i,"last_name");
echo "<option>$authors</option>";
$++; }
mysql_close(); ?>
</select>
</body>
</html>
********************************************
any suggestions would be more than appreciated
Many thnx
Cheers
I want to populate a few drop down boxes using PHP. However i have tried many examples i found from the web but the select box does not get any values. Below i have one example i have tried.
**********************************************
<?php
$link = mysql_connect("localhost", "root", "password") or die("Could not connect: " . mysql_error());
mysql_select_db('db', $link) or die (mysql_error());
$query = "SELECT last_name FROM main_author order by last_name";
$result = mysql_query($query) or die("Couldnt' execute query.");
$num = mysql_numrows($result);
?>
<html>
<body>
<form name="test" id="test" method="post">
<select value="" size="1" name="test2">
<option>all</option>
<? $i=0; while ($i<$num)
{$authors=mysql_result($result,$i,"last_name");
echo "<option>$authors</option>";
$++; }
mysql_close(); ?>
</select>
</body>
</html>
********************************************
any suggestions would be more than appreciated
Many thnx
Cheers
•
•
•
•
Dear all
<?php $link = mysql_connect("localhost", "root", "password") or die("Could not connect: " . mysql_error()); mysql_select_db('db', $link) or die (mysql_error()); $query = "SELECT last_name FROM main_author order by last_name"; $result = mysql_query($query) or die("Couldnt' execute query."); $num = mysql_numrows($result); ?> <html> <body> <form name="test" id="test" method="post"> <select value="" size="1" name="test2"> <option>all</option> <? $i=0; while ($i<$num) { $row = mysql_fetch_assoc($result); echo "<option>$row['last_name']</option>"; $i++; } mysql_close(); ?> </select> </body> </html> ********************************************
Try that and see if it works
Just loop thru the result using the array and print them
StatiX
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Smart chained select boxes (JavaScript / DHTML / AJAX)
- Select Box populates text field (JavaScript / DHTML / AJAX)
- bringing data from mysql using select box (PHP)
- passing values of Select box from JSP to Action class thru form Bean (JSP)
- Paasing the values of Combo Box (PHP)
- Help needed on select option (multible) [list box] (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: Problems with PHP mail function.
- Next Thread: PHP Mail with Sender ID


Linear Mode