|
#1
|
|||
|
|||
|
Web Pages...again!
Can anyone point me in the right direction to populate a dropdown menu from a mysql database table using php
I would like to select a companyname from the dropdown and then post this value to the next page. here is what I have but it only return 1 record <select name="select_company"> <option value="0" selected>Select Dept</option> <?php include("connect.php"); $s_id = $_GET['s_id']; $query = "select DISTINCT companyname from Customers"; $result = mysql_query($query); $num_results = mysql_num_rows($result); for ($i=0; $i <$num_results; $i++) $row = mysql_fetch_array($result); $companyname = $row['companyname'];?> <option value="CompanyName"> <?php echo $companyname; ?> </option> <?php #125;?> </select> any help will be great. Thanks in advance Last edited by ianhull; 06-14-2005 at 10:52 AM. |
|
#2
|
||||
|
||||
|
Admin Note: Moved topic. Please post these sort of questions in the Developer's Den.
__________________
Check out the new MSI Factory 2.0! |
|
#3
|
||||
|
||||
|
In PHP the structure of a for loop is like this:
for ( initialize a counter; conditional statement; increment a counter){ do this code; } You have to put your condition in the first set of parantheses and then all your code "to be executed" in the curly braces. |
|
#4
|
||||
|
||||
|
Corey, you have a knack for describing PHP better than any other source I've run across - when will you get to doing a CD on PHP? I know you're not without commitments, but I beg you to shave an hour off a week for a few months to knock something out along these lines! Just a good intro. to PHP course would be all I need to get rolling.
|
|
#5
|
||||
|
||||
|
Thanks. FWIW I pasted that from the web but I get your point, sometimes it's nice to cut the chaff. I bogged myself down bad this year and am currently climbing out of the rubble, but actually I got some work done on the first PHP training CD this weekend, I'll make sure to keep you posted.
|
|
#6
|
||||
|
||||
|
Yeah - it's not that I can't find good info. on PHP all over the web - it's how do I know what to look for in the first place? Like you said - cutting the the chase is so crucial. There's just no time in my life for learning what I need to know to begin learning something. So exasperating.
|
|
#7
|
||||
|
||||
|
True, I would say it's time someone did the same for video too. [wiggles eyebrows]
But seriously if you ever do a training CD we would gladly stock it at Speedy for 50% of net. Heck if you did some good ones we'd probably even meet you halfway on some advertising. |
|
#8
|
|||
|
|||
|
Thanks Corey,
I now have a new problem if anyone can help I have this on my page but it is only printing the first record in the echo $address Can anyone help me in updating the echo $address each time a new company is selected? Thanks in advance Here is what I have: <!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><?php include_once("connect.php"); ?> <title>Untitled Document</title> <meta **********="Content-Type" content="text/html; charset=iso-8859-1" /> <style type="text/css"> <!-- body,td,th { font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; color: #666666; } .style9 { color: #FFFFFF; font-weight: bold; } .style10 {color: #000000} --> </style></head> <body> <table width="100%" cellspacing="0" cellpadding="0"> <tr> <td> </td> </tr> <tr> <td><table width="100%" cellpadding="0"> <tr> <td width="9%"><a href="index.php"><img src="Images/home.jpg" width="88" height="72" border="0" /></a></td> <td width="9%"><a href="view_companies.php"><img src="Images/viewcustomers.jpg" width="88" height="72" border="0" /></a></td> <td width="9%"><a href="add_company.php"><img src="Images/addcustomers.jpg" width="88" height="72" border="0" /></a></td> <td width="9%"><a href="send_letter.php"><img src="Images/sendletter.jpg" width="88" height="72" border="0" /></a></td> <td width="9%"><a href="add_letter.php"><img src="Images/addletter.jpg" width="88" height="72" border="0" /></a></td> <td width="9%"><a href="send_email.php"><img src="Images/sendemail.jpg" width="88" height="72" border="0" /></a></td> <td width="10%"><div align="left"><a href="logout.php"><img src="Images/logout.jpg" width="88" height="72" border="0" /></a></div></td> <td width="36%" valign="bottom"></td> </tr> <tr bgcolor="#D51B0C"> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td><span class="style9"> </span> <table width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="3%"><span class="style9"> </span></td> <td width="97%"><span class="style9"> </span></td> </tr> </table> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table></td> </tr> <tr> <td><table width="100%" cellspacing="0" cellpadding="0"> <tr> <td width="68%"><table width="97%" cellspacing="0" cellpadding="0"> <tr> <td width="2%" height="75" valign="top"><div align="left"><span class="style10"></span></div></td> <td width="98%" valign="top"><table width="100%" cellspacing="0" cellpadding="0"> <tr> <td><strong>Today is:</strong> <?php echo date("l dS of F Y h:i:s A"); ?> </td> </tr> <tr> <td class="style10"> </td> </tr> <tr> <td class="style10"> </td> </tr> <tr> <td class="style10"> </td> </tr> <tr> <td class="style10">Please Select a Company </td> </tr> </table></td> </tr> <tr> <td height="30"><div align="left"></div></td> <td valign="top"> <?php $sql = "SELECT DISTINCT companyname, address from customers ORDER BY companyname"; $result = mysql_query($sql) or die ("Couldn't select Companies"); echo " <select name='companyname'>\n"; //-------------get each event type ------ while ($line = mysql_fetch_array($result)) { extract($line); // extracts all line into variables with same name as fields echo "<option value='$companyname' "; if ($companyname==$companyname) echo "selected"; echo ">$companyname\n"; } echo "</select> </td></tr>\n"; ?> </td> </tr> <tr> <td><div align="left"></div></td> <td> </td> </tr> <tr> <td><div align="left"></div></td> <td> </td> </tr> <tr> <td><div align="left"></div></td> <td>The Address for the company you selected is: <?php echo $address ?></td> </tr> </table></td> <td width="32%"> </td> </tr> </table></td> </tr> </table> </body> </html> |
|
#9
|
||||
|
||||
|
Just at a glance I'd say this is one problem:
if ($companyname==$companyname) That statement will always result in "true" when compared because you are assessing a value against itself... |
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to interrupt mailto: on web pages? | gnetcanada | AutoPlay Media Studio 5.0 | 1 | 01-09-2005 11:21 AM |
| Interacting with Embedded Web Objects | Desmond | AutoPlay Media Studio 5.0 Examples | 0 | 10-01-2003 03:17 PM |
| HOW TO: Return a Web Browser Object to the Original URL after a Page Jump | Support | AutoPlay Media Studio 4.0 Examples | 0 | 02-03-2003 10:18 AM |
| Frames Based Web Pages a Problem | Ian Johnson | AutoPlay Media Studio 4.0 | 2 | 01-22-2003 08:16 PM |
| Linking to locally stored Web pages | acooney | AutoPlay Menu Studio 3.0 | 2 | 04-06-2000 04:02 PM |
All times are GMT -6. The time now is 12:10 AM.








Linear Mode

