guymclaren Posted September 12, 2007 Share Posted September 12, 2007 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 More sharing options...
watthehell Posted September 12, 2007 Share Posted September 12, 2007 where is the while loop to fetch all the data ??? ??? ??? ??? Link to comment https://forums.phpfreaks.com/topic/68991-output-not-expected/#findComment-346781 Share on other sites More sharing options...
xyn Posted September 12, 2007 Share Posted September 12, 2007 <?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 More sharing options...
xyn Posted September 12, 2007 Share Posted September 12, 2007 where is the while loop to fetch all the data ??? ??? ??? ??? using mysql_result() I dont think you need the array.. however i'm not too sure about mysql_result i avoid its sufe where possible Link to comment https://forums.phpfreaks.com/topic/68991-output-not-expected/#findComment-346783 Share on other sites More sharing options...
guymclaren Posted September 12, 2007 Author Share Posted September 12, 2007 I am expecting a single result, so the array should not be neccessary or am I mistaken? Link to comment https://forums.phpfreaks.com/topic/68991-output-not-expected/#findComment-346787 Share on other sites More sharing options...
xyn Posted September 12, 2007 Share Posted September 12, 2007 Even if its a single result; the array is required such as in my example Link to comment https://forums.phpfreaks.com/topic/68991-output-not-expected/#findComment-346789 Share on other sites More sharing options...
guymclaren Posted September 12, 2007 Author Share Posted September 12, 2007 Thank you, I will try that. It seems that ASP and PHP have many differences in logic. Link to comment https://forums.phpfreaks.com/topic/68991-output-not-expected/#findComment-346796 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.