PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ianhull
Forum Contributor
Posts: 310 Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK
Post
by ianhull » Thu Jun 16, 2005 6:15 am
Hi, 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
Code: Select all
<?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><?php echo $address ?>
</td>
</tr>
<tr>
<td><div align="left"></div></td>
<td> </td>
</tr>
<tr>
<td><div align="left"></div></td>
<td> </td>
</tr>
</table>
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Thu Jun 16, 2005 6:43 am
you need to change your sql
Code: Select all
$sql = "SELECT DISTINCT companyname, address FROM customers WHERE companyname = '".$_POST['companyname']."' ORDER BY companyname";
Something liek that anyway...i cant see your all your code so cant help further
ianhull
Forum Contributor
Posts: 310 Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK
Post
by ianhull » Thu Jun 16, 2005 6:58 am
Code: Select all
<!DOCTYPE html PUBLIC "e;-//W3C//DTD XHTML 1.0 Transitional//EN"e; "e;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"e;>
<html xmlns="e;http://www.w3.org/1999/xhtml"e;>
<head><?php
include_once("e;connect.php"e;);
?>
<title>Untitled Document</title>
<meta http-equiv="e;Content-Type"e; content="e;text/html; charset=iso-8859-1"e; />
<style type="e;text/css"e;>
<!--
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="e;100%"e; cellspacing="e;0"e; cellpadding="e;0"e;>
<tr>
<td> </td>
</tr>
<tr>
<td><table width="e;100%"e; cellpadding="e;0"e;>
<tr>
<td width="e;9%"e;><a href="e;index.php"e;><img src="e;Images/home.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></td>
<td width="e;9%"e;><a href="e;view_companies.php"e;><img src="e;Images/viewcustomers.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></td>
<td width="e;9%"e;><a href="e;add_company.php"e;><img src="e;Images/addcustomers.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></td>
<td width="e;9%"e;><a href="e;send_letter.php"e;><img src="e;Images/sendletter.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></td>
<td width="e;9%"e;><a href="e;add_letter.php"e;><img src="e;Images/addletter.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></td>
<td width="e;9%"e;><a href="e;send_email.php"e;><img src="e;Images/sendemail.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></td>
<td width="e;10%"e;><div align="e;left"e;><a href="e;logout.php"e;><img src="e;Images/logout.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></div></td>
<td width="e;36%"e; valign="e;bottom"e;></td>
</tr>
<tr bgcolor="e;#D51B0C"e;>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><span class="e;style9"e;>
</span>
<table width="e;100%"e; cellspacing="e;0"e; cellpadding="e;0"e;>
<tr>
<td width="e;3%"e;><span class="e;style9"e;>
</span></td>
<td width="e;97%"e;><span class="e;style9"e;>
</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="e;100%"e; cellspacing="e;0"e; cellpadding="e;0"e;>
<tr>
<td width="e;68%"e;><table width="e;97%"e; cellspacing="e;0"e; cellpadding="e;0"e;>
<tr>
<td width="e;2%"e; height="e;75"e; valign="e;top"e;><div align="e;left"e;><span class="e;style10"e;></span></div></td>
<td width="e;98%"e; valign="e;top"e;><table width="e;100%"e; cellspacing="e;0"e; cellpadding="e;0"e;>
<tr>
<td><strong>Today is:</strong>
<?php
echo date("e;l dS of F Y h:i:s A"e;);
?>
</td>
</tr>
<tr>
<td class="e;style10"e;> </td>
</tr>
<tr>
<td class="e;style10"e;> </td>
</tr>
<tr>
<td class="e;style10"e;> </td>
</tr>
<tr>
<td class="e;style10"e;>Please Select a Company </td>
</tr>
</table></td>
</tr>
<tr>
<td height="e;30"e;><div align="e;left"e;></div></td>
<td valign="e;top"e;>
<?php
$sql = "e;SELECT DISTINCT companyname, address from customers ORDER BY companyname"e;;
$result = mysql_query($sql)
or die ("e;Couldn't select Companies"e;);
echo "e;
<select name='companyname'>\n"e;;
//-------------get each event type ------
while ($line = mysql_fetch_array($result))
{
extract($line); // extracts all line into variables with same name as fields
echo "e;<option value='$companyname' "e;;
if ($companyname==$companyname) echo "e;selected"e;;
echo "e;>$companyname\n"e;;
}
echo "e;</select> </td></tr>\n"e;;
?>
</td>
</tr>
<tr>
<td><div align="e;left"e;></div></td>
<td>
</td>
</tr>
<tr>
<td><div align="e;left"e;></div></td>
<td> </td>
</tr>
<tr>
<td><div align="e;left"e;></div></td>
<td>The Address for the company you selected is: <?php echo $address ?></td>
</tr>
</table></td>
<td width="e;32%"e;>
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
ianhull
Forum Contributor
Posts: 310 Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK
Post
by ianhull » Thu Jun 16, 2005 6:59 am
Here is my full code,
I tried using your sql but it did not work, if you can help any further it will be much appreciated.
Thanks
Code: Select all
<!DOCTYPE html PUBLIC "e;-//W3C//DTD XHTML 1.0 Transitional//EN"e; "e;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"e;>
<html xmlns="e;http://www.w3.org/1999/xhtml"e;>
<head><?php
include_once("e;connect.php"e;);
?>
<title>Untitled Document</title>
<meta http-equiv="e;Content-Type"e; content="e;text/html; charset=iso-8859-1"e; />
<style type="e;text/css"e;>
<!--
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="e;100%"e; cellspacing="e;0"e; cellpadding="e;0"e;>
<tr>
<td> </td>
</tr>
<tr>
<td><table width="e;100%"e; cellpadding="e;0"e;>
<tr>
<td width="e;9%"e;><a href="e;index.php"e;><img src="e;Images/home.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></td>
<td width="e;9%"e;><a href="e;view_companies.php"e;><img src="e;Images/viewcustomers.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></td>
<td width="e;9%"e;><a href="e;add_company.php"e;><img src="e;Images/addcustomers.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></td>
<td width="e;9%"e;><a href="e;send_letter.php"e;><img src="e;Images/sendletter.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></td>
<td width="e;9%"e;><a href="e;add_letter.php"e;><img src="e;Images/addletter.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></td>
<td width="e;9%"e;><a href="e;send_email.php"e;><img src="e;Images/sendemail.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></td>
<td width="e;10%"e;><div align="e;left"e;><a href="e;logout.php"e;><img src="e;Images/logout.jpg"e; width="e;88"e; height="e;72"e; border="e;0"e; /></a></div></td>
<td width="e;36%"e; valign="e;bottom"e;></td>
</tr>
<tr bgcolor="e;#D51B0C"e;>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><span class="e;style9"e;>
</span>
<table width="e;100%"e; cellspacing="e;0"e; cellpadding="e;0"e;>
<tr>
<td width="e;3%"e;><span class="e;style9"e;>
</span></td>
<td width="e;97%"e;><span class="e;style9"e;>
</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="e;100%"e; cellspacing="e;0"e; cellpadding="e;0"e;>
<tr>
<td width="e;68%"e;><table width="e;97%"e; cellspacing="e;0"e; cellpadding="e;0"e;>
<tr>
<td width="e;2%"e; height="e;75"e; valign="e;top"e;><div align="e;left"e;><span class="e;style10"e;></span></div></td>
<td width="e;98%"e; valign="e;top"e;><table width="e;100%"e; cellspacing="e;0"e; cellpadding="e;0"e;>
<tr>
<td><strong>Today is:</strong>
<?php
echo date("e;l dS of F Y h:i:s A"e;);
?>
</td>
</tr>
<tr>
<td class="e;style10"e;> </td>
</tr>
<tr>
<td class="e;style10"e;> </td>
</tr>
<tr>
<td class="e;style10"e;> </td>
</tr>
<tr>
<td class="e;style10"e;>Please Select a Company </td>
</tr>
</table></td>
</tr>
<tr>
<td height="e;30"e;><div align="e;left"e;></div></td>
<td valign="e;top"e;>
<?php
$sql = "e;SELECT DISTINCT companyname, address from customers ORDER BY companyname"e;;
$result = mysql_query($sql)
or die ("e;Couldn't select Companies"e;);
echo "e;
<select name='companyname'>\n"e;;
//-------------get each event type ------
while ($line = mysql_fetch_array($result))
{
extract($line); // extracts all line into variables with same name as fields
echo "e;<option value='$companyname' "e;;
if ($companyname==$companyname) echo "e;selected"e;;
echo "e;>$companyname\n"e;;
}
echo "e;</select> </td></tr>\n"e;;
?>
</td>
</tr>
<tr>
<td><div align="e;left"e;></div></td>
<td>
</td>
</tr>
<tr>
<td><div align="e;left"e;></div></td>
<td> </td>
</tr>
<tr>
<td><div align="e;left"e;></div></td>
<td>The Address for the company you selected is: <?php echo $address ?></td>
</tr>
</table></td>
<td width="e;32%"e;>
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>