Jump to content

Recommended Posts

Please look at this and tell me why I am getting the strange output

 

$Contact="SELECT contact_address, contact_postal, contact_tel, contact_fax, contact_skype, contact_messenger FROM contacts WHERE contact_site ='".$siteID. "'";

$objcontact=mysql_query($Contact);

$countcontact=mysql_numrows($objcontact);

?>

<div id="sidebar">

<div id="menu">

<?

if ($countcontact==0) {

} else {

 

$caddress=mysql_result($objcontact,"contact_address");

$cpostal=mysql_result($objcontact,"contact_postal");

$ctel=mysql_result($objcontact,"contact_tel");

$cfax=mysql_result($objcontact,"contact_fax");

$cskype=mysql_result($objcontact,"contact_skype");

$cmessenger=mysql_result($objcontact,"contact_messenger");

 

?>

<h3>Contact Us</h3><ul>

<?// Carry on here

If (strlen($caddress) > 0) {

?> <li><strong>Physical Address:</strong><br> <? echo $caddress; ?></li>

<? }

If (strlen($cpostal) > 0) {

?> <li><strong>Postal Address:</strong><br> <? echo $cpostal; ?></li>

<? }

If (strlen($ctel) > 0) {

?> <li><strong>Telephone:</strong><br>  <? echo $ctel; ?></li>

<? }

If (strlen($cfax) > 0) {

?><li> <strong>Facsimile:</strong><br> <? echo $cfax; ?></li>

<? }

If (strlen($cskype) > 0) {

?> <li><strong>Skype:</strong><br> <? echo $cskype; ?></li>

<? }

If (strlen($cmessenger) > 0) {

?> <li><strong>Messenger:</strong><br> <? echo $cmessenger; ?></li>

<? }?>

 

 

<li><a href="subscribe.php">Send an email</a></li>

</ul>

 

<?

}?>

 

 

Output

 

# Physical Address:

20 Norma Str

Sonheuwel

Nelspruit

1200

# Postal Address:

20 Norma Str

Sonheuwel

Nelspruit

1200

# Telephone:

20 Norma Str

Sonheuwel

Nelspruit

1200

# Facsimile:

20 Norma Str

Sonheuwel

Nelspruit

1200

# Skype:

20 Norma Str

Sonheuwel

Nelspruit

1200

# Messenger:

20 Norma Str

Sonheuwel

Nelspruit

1200

 

It repeats the address over and over rather than imputting the correct data. I am beyond confused. This works in ASP but in my desire to convert to PHP I am being stymied.

Link to comment
https://forums.phpfreaks.com/topic/68991-output-not-expected/
Share on other sites

<?php
$objcontact = mysql_query("SELECT contact_address, contact_postal, contact_tel, contact_fax, contact_skype, contact_messenger FROM contacts WHERE contact_site ='".$siteID. "'"); # Query

if(mysql_num_rows($objcontact)>0)	#	More then 0 rows.
{
while($data = mysql_fetch_array($objcontact))	#	Creates an array
{
?>
	$contact_address = $data[0];
	$contact_postal = $data[1];
	$contact_tel = $data[2];
	$contact_fax = $data[3];
	$contact_skype = $data[4];
	$contact_messenger = $data[5];
	<h3>Contact Us</h3><ul>
<?php #	Carry on here
If (strlen($caddress) > 0) {
?> <li><strong>Physical Address:</strong>
<?=$contact_address;?></li>
<? }
If (strlen($cpostal) > 0) {
?> <li><strong>Postal Address:</strong>
<?=$contact_postal;?></li>
<? }
If (strlen($ctel) > 0) {
?> <li><strong>Telephone:</strong>
 <?=$contact_tel;?></li>
<? }
If (strlen($cfax) > 0) {
?><li> <strong>Facsimile:</strong>
<?=$contact_fax;?></li>
<? }
If (strlen($cskype) > 0) {
?> <li><strong>Skype:</strong>
<?=$contact_skype;?></li>
<? }
If (strlen($cmessenger) > 0) {
?> <li><strong>Messenger:</strong>
<?=$contact_messenger;?></li>
<? }?>


<li><a href="subscribe.php">Send an email[/url]</li>
</ul>

<?
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/68991-output-not-expected/#findComment-346782
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.