View Single Post
  #4   Spotlight this post!  
Unread 28-06-2004, 17:37
Joshua May's Avatar
Joshua May Joshua May is offline
Go Bears!
FRC #1110 (Binary Bulldogs)
Team Role: College Student
 
Join Date: Nov 2003
Rookie Year: 2003
Location: Berkeley, CA
Posts: 1,306
Joshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond reputeJoshua May has a reputation beyond repute
Send a message via AIM to Joshua May
Re: PHP, MySQL, and Dropdown lists

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.
__________________
The FIRST Wiki - openFIRST - Ultimate Robot Challenge - URC Wiki
I currently have 50 GMail invites, PM or email me for one.
UC Berkeley Class of 2009

2005 Las Vegas Regional Autodesk Visualization Award
2005 Las Vegas Regional #8 Seeded Alliance with 988 and 1505
2006 Southern California Regional #15 seed