Page 1 of 1

How to update echo

Posted: Thu Jun 16, 2005 6:15 am
by ianhull
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>&nbsp;</td>
          </tr>
          <tr>
            <td><div align="left"></div></td>
            <td>&nbsp;</td>
          </tr>
        </table>

Posted: Thu Jun 16, 2005 6:43 am
by JayBird
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

Posted: Thu Jun 16, 2005 6:58 am
by ianhull

Code: Select all

<!DOCTYPE html PUBLIC &quote;-//W3C//DTD XHTML 1.0 Transitional//EN&quote; &quote;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quote;>
<html xmlns=&quote;http://www.w3.org/1999/xhtml&quote;>
<head><?php 
		include_once(&quote;connect.php&quote;); 
 
?>
<title>Untitled Document</title>
<meta http-equiv=&quote;Content-Type&quote; content=&quote;text/html; charset=iso-8859-1&quote; />
<style type=&quote;text/css&quote;>
<!--
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=&quote;100%&quote;  cellspacing=&quote;0&quote; cellpadding=&quote;0&quote;>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><table width=&quote;100%&quote; cellpadding=&quote;0&quote;>
      <tr>
        <td width=&quote;9%&quote;><a href=&quote;index.php&quote;><img src=&quote;Images/home.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></td>
        <td width=&quote;9%&quote;><a href=&quote;view_companies.php&quote;><img src=&quote;Images/viewcustomers.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></td>
        <td width=&quote;9%&quote;><a href=&quote;add_company.php&quote;><img src=&quote;Images/addcustomers.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></td>
        <td width=&quote;9%&quote;><a href=&quote;send_letter.php&quote;><img src=&quote;Images/sendletter.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></td>
        <td width=&quote;9%&quote;><a href=&quote;add_letter.php&quote;><img src=&quote;Images/addletter.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></td>
        <td width=&quote;9%&quote;><a href=&quote;send_email.php&quote;><img src=&quote;Images/sendemail.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></td>
        <td width=&quote;10%&quote;><div align=&quote;left&quote;><a href=&quote;logout.php&quote;><img src=&quote;Images/logout.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></div></td>
        <td width=&quote;36%&quote; valign=&quote;bottom&quote;></td>
      </tr>
      <tr bgcolor=&quote;#D51B0C&quote;>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><span class=&quote;style9&quote;>
</span>
          <table width=&quote;100%&quote;  cellspacing=&quote;0&quote; cellpadding=&quote;0&quote;>
            <tr>
              <td width=&quote;3%&quote;><span class=&quote;style9&quote;>
              </span></td>
              <td width=&quote;97%&quote;><span class=&quote;style9&quote;>
              </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=&quote;100%&quote;  cellspacing=&quote;0&quote; cellpadding=&quote;0&quote;>
      <tr>
        <td width=&quote;68%&quote;><table width=&quote;97%&quote;  cellspacing=&quote;0&quote; cellpadding=&quote;0&quote;>
          <tr>
            <td width=&quote;2%&quote; height=&quote;75&quote; valign=&quote;top&quote;><div align=&quote;left&quote;><span class=&quote;style10&quote;></span></div></td>
            <td width=&quote;98%&quote; valign=&quote;top&quote;><table width=&quote;100%&quote;  cellspacing=&quote;0&quote; cellpadding=&quote;0&quote;>
              <tr>
                <td><strong>Today is:</strong> 
                    <?php
echo date(&quote;l dS of F Y h:i:s A&quote;);
?>
                </td>
              </tr>
              <tr>
                <td class=&quote;style10&quote;>&nbsp;</td>
              </tr>
              <tr>
                <td class=&quote;style10&quote;>&nbsp;</td>
              </tr>
              <tr>
                <td class=&quote;style10&quote;>&nbsp;</td>
              </tr>
              <tr>
                <td class=&quote;style10&quote;>Please Select a Company </td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td height=&quote;30&quote;><div align=&quote;left&quote;></div></td>
           <td valign=&quote;top&quote;>
<?php
$sql = &quote;SELECT DISTINCT companyname, address from customers ORDER BY companyname&quote;;

$result = mysql_query($sql)
 or die (&quote;Couldn't select Companies&quote;);

echo &quote;

<select name='companyname'>\n&quote;;

//-------------get each event type ------

while ($line = mysql_fetch_array($result))    
      {
      extract($line);      // extracts all line into variables with same name as fields 
      echo &quote;<option value='$companyname' &quote;;
      if ($companyname==$companyname) echo &quote;selected&quote;;
      echo &quote;>$companyname\n&quote;;
      }
echo &quote;</select>  </td></tr>\n&quote;;


?>
</td>
          </tr>
          <tr>
            <td><div align=&quote;left&quote;></div></td>
            <td>&nbsp;
			</td>
          </tr>
          <tr>
            <td><div align=&quote;left&quote;></div></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td><div align=&quote;left&quote;></div></td>
            <td>The Address for the company you selected is:  <?php echo  $address ?></td>
          </tr>
        </table></td>
        <td width=&quote;32%&quote;>
</td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>

Posted: Thu Jun 16, 2005 6:59 am
by ianhull
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 &quote;-//W3C//DTD XHTML 1.0 Transitional//EN&quote; &quote;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quote;>
<html xmlns=&quote;http://www.w3.org/1999/xhtml&quote;>
<head><?php 
		include_once(&quote;connect.php&quote;); 
 
?>
<title>Untitled Document</title>
<meta http-equiv=&quote;Content-Type&quote; content=&quote;text/html; charset=iso-8859-1&quote; />
<style type=&quote;text/css&quote;>
<!--
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=&quote;100%&quote;  cellspacing=&quote;0&quote; cellpadding=&quote;0&quote;>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><table width=&quote;100%&quote; cellpadding=&quote;0&quote;>
      <tr>
        <td width=&quote;9%&quote;><a href=&quote;index.php&quote;><img src=&quote;Images/home.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></td>
        <td width=&quote;9%&quote;><a href=&quote;view_companies.php&quote;><img src=&quote;Images/viewcustomers.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></td>
        <td width=&quote;9%&quote;><a href=&quote;add_company.php&quote;><img src=&quote;Images/addcustomers.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></td>
        <td width=&quote;9%&quote;><a href=&quote;send_letter.php&quote;><img src=&quote;Images/sendletter.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></td>
        <td width=&quote;9%&quote;><a href=&quote;add_letter.php&quote;><img src=&quote;Images/addletter.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></td>
        <td width=&quote;9%&quote;><a href=&quote;send_email.php&quote;><img src=&quote;Images/sendemail.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></td>
        <td width=&quote;10%&quote;><div align=&quote;left&quote;><a href=&quote;logout.php&quote;><img src=&quote;Images/logout.jpg&quote; width=&quote;88&quote; height=&quote;72&quote; border=&quote;0&quote; /></a></div></td>
        <td width=&quote;36%&quote; valign=&quote;bottom&quote;></td>
      </tr>
      <tr bgcolor=&quote;#D51B0C&quote;>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><span class=&quote;style9&quote;>
</span>
          <table width=&quote;100%&quote;  cellspacing=&quote;0&quote; cellpadding=&quote;0&quote;>
            <tr>
              <td width=&quote;3%&quote;><span class=&quote;style9&quote;>
              </span></td>
              <td width=&quote;97%&quote;><span class=&quote;style9&quote;>
              </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=&quote;100%&quote;  cellspacing=&quote;0&quote; cellpadding=&quote;0&quote;>
      <tr>
        <td width=&quote;68%&quote;><table width=&quote;97%&quote;  cellspacing=&quote;0&quote; cellpadding=&quote;0&quote;>
          <tr>
            <td width=&quote;2%&quote; height=&quote;75&quote; valign=&quote;top&quote;><div align=&quote;left&quote;><span class=&quote;style10&quote;></span></div></td>
            <td width=&quote;98%&quote; valign=&quote;top&quote;><table width=&quote;100%&quote;  cellspacing=&quote;0&quote; cellpadding=&quote;0&quote;>
              <tr>
                <td><strong>Today is:</strong> 
                    <?php
echo date(&quote;l dS of F Y h:i:s A&quote;);
?>
                </td>
              </tr>
              <tr>
                <td class=&quote;style10&quote;>&nbsp;</td>
              </tr>
              <tr>
                <td class=&quote;style10&quote;>&nbsp;</td>
              </tr>
              <tr>
                <td class=&quote;style10&quote;>&nbsp;</td>
              </tr>
              <tr>
                <td class=&quote;style10&quote;>Please Select a Company </td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td height=&quote;30&quote;><div align=&quote;left&quote;></div></td>
           <td valign=&quote;top&quote;>
<?php
$sql = &quote;SELECT DISTINCT companyname, address from customers ORDER BY companyname&quote;;

$result = mysql_query($sql)
 or die (&quote;Couldn't select Companies&quote;);

echo &quote;

<select name='companyname'>\n&quote;;

//-------------get each event type ------

while ($line = mysql_fetch_array($result))    
      {
      extract($line);      // extracts all line into variables with same name as fields 
      echo &quote;<option value='$companyname' &quote;;
      if ($companyname==$companyname) echo &quote;selected&quote;;
      echo &quote;>$companyname\n&quote;;
      }
echo &quote;</select>  </td></tr>\n&quote;;


?>
</td>
          </tr>
          <tr>
            <td><div align=&quote;left&quote;></div></td>
            <td>&nbsp;
			</td>
          </tr>
          <tr>
            <td><div align=&quote;left&quote;></div></td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td><div align=&quote;left&quote;></div></td>
            <td>The Address for the company you selected is:  <?php echo  $address ?></td>
          </tr>
        </table></td>
        <td width=&quote;32%&quote;>
</td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>