Current location: Hot Scripts Forums » Programming Languages » PHP » Function and variable problem


Function and variable problem

Reply
  #1 (permalink)  
Old 02-11-04, 01:43 PM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
Function and variable problem

Hi, i have a function, that creates the code for a HTML table. Within that function i have a variable, called $title. This contains text, which is declared on each page, that is shown in the table, i have put

PHP Code:

 global $title
in the function, but it doesnt show.

This function is used for blocks for a menu, each block has its own file, which is included, and within the file, is the declaration for the variable.

Heres the code for the function

PHP Code:

 function block_open() { 

global 
$title
        echo 
"<table align=\"center\" bgcolor=\"#000000\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"100%\">"
        echo 
"<tr bgcolor=\"#009999\">"
        echo 
"<td class=\"content-menu-cat\" bgcolor=\"#008080\"><span class=\"content-menu-cat\"><font face=\"Arial, Helvetica, sans-serif\" color=\"#FFFFFF\"><img src=\"images/icon.gif\" alt=\"\" align=\"left\" />"
        echo 
$title
        echo 
"</font></span></td>"
        echo 
"</tr>"
        echo 
"<tr bgcolor=\"#FFFFFF\">"
        echo 
"<td>"
                       } 
             
            
//close table                       
function block_close() { 
        echo 
"</td>"
        echo 
"</tr>"
        echo 
"</table>"
        echo 
"<table><tr><td></td></tr></table>"
                       } 

Then a typical block file looks like this

PHP Code:



 $title 
'Navigation'
block_open(); 


block_close(); 
But the $title doesnt show!!
Reply With Quote
  #2 (permalink)  
Old 02-11-04, 08:52 PM
tltran tltran is offline
Newbie Coder
 
Join Date: Jan 2004
Location: Montreal
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Here is how to do that.

global.php

<?php
global $my_var;

$my_var = "<br>Hi There";
?>

f1.php
<?php
function f1(){
global $my_var;
echo "<br>=====";
}

?>


f2.php
<?php
function f2(){
global $my_var;
echo $my_var;
echo "<br>=====";
}
?>

index.php (the execution script)
<?php
include_once("global.php");
include_once("f1.php");
include_once("f2.php");

f1();
f2();
// change the value of the variable
$my_var = "Change after f2";
f1();
f2();

?>
__________________
Thanh Liem Tran
When You have to run, you have to run
http://www.irunsoft.com
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
InStr function in vb script lunatchi ASP 2 01-21-04 08:05 AM
Object Oriented Programming Stefan PHP 29 12-30-03 11:22 AM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM
Php Variable phppick PHP 4 08-15-03 08:54 PM
Php Variable Urgent phppick PHP 1 08-14-03 06:31 AM


All times are GMT -5. The time now is 08:47 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.