Indigo Rose Software
  #1  
Old 06-14-2005
ianhull ianhull is offline
Forum Member
 
Join Date: Jul 2004
Posts: 313
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.
Reply With Quote
  #2  
Old 06-14-2005
Ted Sullivan's Avatar
Ted Sullivan Ted Sullivan is offline
Indigo Rose Staff Member
 
Join Date: Oct 2003
Posts: 825
Admin Note: Moved topic. Please post these sort of questions in the Developer's Den.
__________________
Check out the new MSI Factory 2.0!
Reply With Quote
  #3  
Old 06-14-2005
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
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.
Reply With Quote
  #4  
Old 06-14-2005
eric_darling's Avatar
eric_darling eric_darling is offline
Indigo Rose Customer
 
Join Date: Jun 2002
Location: Southeast USA
Posts: 1,804
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.
__________________
Eric Darling
eThree Media
http://www.ethreemedia.com
Reply With Quote
  #5  
Old 06-14-2005
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
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.
Reply With Quote
  #6  
Old 06-14-2005
eric_darling's Avatar
eric_darling eric_darling is offline
Indigo Rose Customer
 
Join Date: Jun 2002
Location: Southeast USA
Posts: 1,804
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.
__________________
Eric Darling
eThree Media
http://www.ethreemedia.com
Reply With Quote
  #7  
Old 06-14-2005
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
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.
Reply With Quote
  #8  
Old 06-16-2005
ianhull ianhull is offline
Forum Member
 
Join Date: Jul 2004
Posts: 313
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>&nbsp;</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>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</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>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</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">&nbsp;</td>
</tr>
<tr>
<td class="style10">&nbsp;</td>
</tr>
<tr>
<td class="style10">&nbsp;</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>&nbsp;
</td>
</tr>
<tr>
<td><div align="left"></div></td>
<td>&nbsp;</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>
Reply With Quote
  #9  
Old 06-16-2005
Corey's Avatar
Corey Corey is offline
Registered User
 
Join Date: Aug 2002
Posts: 9,746
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...
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


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.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software