You are here: Odd function problem « All PHP « IT news, forums, messages
Odd function problem

Posted by gerg on 12/15/05 02:04

I have an odd thing happening. Can you reference variable that are set
above a function? The below code is not working for me:


<?
$sql ="some sql query";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$msg = nl2br($row['message']);

function mycontent(){
?>

Some html code............
<?
echo $msg;
?>
Some more html code.......

<?
}
?>


However this does work:

function mycontent(){
?>

Some html code............
<?
$sql ="some sql query";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$msg = nl2br($row['message']);
echo $msg;
?>
Some more html code.......

<?
}
?>

Any reason why it works when the variables are inside the function as
opposed to being outside of it? Thanks!

Greg

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация