brown2005 Posted January 22, 2007 Share Posted January 22, 2007 hi, i have the following function;function WebsiteCost(){ $WebsiteCost_sql = "SELECT * FROM z_website WHERE website_title='COST' LIMIT 1;"; $WebsiteCost_query = mysql_query($WebsiteCost_sql) or die(mysql_error()); while($WebsiteCost_array = mysql_fetch_array($WebsiteCost_query)) { $WebsiteCost = $WebsiteCost_array['website_text']; return $WebsiteCost; }}then echo WebsiteCost();will echo £5, but what i wanted to know is can you have two values in the function i.e. function WebsiteCost(){ $WebsiteCost_sql = "SELECT * FROM z_website WHERE website_title='COST' LIMIT 1;"; $WebsiteCost_query = mysql_query($WebsiteCost_sql) or die(mysql_error()); while($WebsiteCost_array = mysql_fetch_array($WebsiteCost_query)) { $WebsiteCost = $WebsiteCost_array['website_text']; $WebsiteCostDisplay = "£ $WebsiteCost.00"; return $WebsiteCost; }}and how can i echo out the $WebsiteCostDisplay if you can? PLEASE Link to comment https://forums.phpfreaks.com/topic/35210-functions/ Share on other sites More sharing options...
trq Posted January 22, 2007 Share Posted January 22, 2007 If you want to return more then one value you will need to use an array. Example.[code]<?php function foo() { $a = 5; $b = 10; return array($a,$b); } $foo = foo(); echo $foo[0]; echo $foo[1];?>[/code] Link to comment https://forums.phpfreaks.com/topic/35210-functions/#findComment-166257 Share on other sites More sharing options...
brown2005 Posted January 22, 2007 Author Share Posted January 22, 2007 Thanks very much, when i do it with $WebsiteCost = $WebsiteCost_array['website_text'];$WebsiteCostDisplay = "£$WebsiteCost.00";it prints5£.00and should print5£5.00any ideas please? Link to comment https://forums.phpfreaks.com/topic/35210-functions/#findComment-166273 Share on other sites More sharing options...
trq Posted January 22, 2007 Share Posted January 22, 2007 $WebsiteCost must be empty. Link to comment https://forums.phpfreaks.com/topic/35210-functions/#findComment-166277 Share on other sites More sharing options...
brown2005 Posted January 22, 2007 Author Share Posted January 22, 2007 sorry my mistake dont know wat I did but it works now.. thanks for all your help Link to comment https://forums.phpfreaks.com/topic/35210-functions/#findComment-166280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.