Quote:
|
Originally Posted by Raven_Writer
I have a question. Is it possible to get all the fields from a table inside a MySQL database, and display 'em, one by one, inside a dropdown list? I'm pretty sure it is, but I don't want to do 3+ hr.'s of coding to find out it won't work.
|
Haven't tested it, adn there are probably syntax errors, but this might work.
PHP Code:
<?php
$username = "username";
$password = "password";
$database = "database";
$link = mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query("SELECT * FROM table",$link) or die ("Mysql error: ".mysql_error());
$num = mysql_num_rows($result);
echo "<form name=\"mysql_test\">";
echo "<select size=\"1\" name=\"mysql\">";
$i=0;
while ($i < $num) {
$field1 = mysql_result($result,$i,"field1");
echo "<option>$field1</option>";
$i++;
}
$i=0;
while ($i < $num) {
$field2 = mysql_result($result,$i,"field2");
echo "<option>$field2</option>";
$i++;
}
echo "</select>";
echo "</form>";
mysql_close();
?>
Hopefully that gives you an idea of what I'm trying to say. It searches through the first field and each time prints the HTML code for each section of a drop down list. Then it runs through the second field and each time prints the HTML code for each section of a drop down list. You would still need to format it to fit into an HTML table if that's what you want to do. Hope this works for you.
__________________
2005 Las Vegas Regional Autodesk Visualization Award
2005 Las Vegas Regional #8 Seeded Alliance with 988 and 1505
2006 Southern California Regional #15 seed