User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 373,375 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,801 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 230 | Replies: 4
Reply
Join Date: Jun 2007
Posts: 51
Reputation: naju is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
naju's Avatar
naju naju is offline Offline
Junior Poster in Training

How can i confirm a fucntion is exec once

  #1  
Mar 18th, 2008
i have a function

lets say
function myfunc()
{
echo 'hi';
}

now the code may call the function myfunc more than a time
but there should be only one time echo of 'hi'

pliz help anything could work .... but all my effort in vain
static variable ????
global variable checking ???
code in a separate file n making include_once ?????


pliz help
Hunters Never Hurt
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Location: Cochin
Posts: 67
Reputation: jino is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Re: How can i confirm a fucntion is exec once

  #2  
Mar 19th, 2008
<?php
function display()
{
echo "hello<br>";
}
while($i<=5)
{
display();
$i++;
}
?>//save this file and include this file in other file using include"filename.php";
Last edited by jino : Mar 19th, 2008 at 2:38 am. Reason: Want to make it more clear
We only have to do a very few things right in our life, so long as we don't do too many things wrong.
Reply With Quote  
Join Date: Jun 2007
Posts: 51
Reputation: naju is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
naju's Avatar
naju naju is offline Offline
Junior Poster in Training

Re: How can i confirm a fucntion is exec once

  #3  
Mar 19th, 2008
i said just a one ...

yes i will be call the function many time from different-different modules

But certain codes inside the function should execute just a once ..... not twice .. not five times....

thank you
Hunters Never Hurt
Reply With Quote  
Join Date: Aug 2006
Posts: 1
Reputation: ha1f is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ha1f ha1f is offline Offline
Newbie Poster

Re: How can i confirm a fucntion is exec once

  #4  
Mar 19th, 2008
If you only want it to show once just use something like

...
if($has_not_displayed)
{
  display();
  $has_not_displayed = FALSE;
}
...
Last edited by ha1f : Mar 19th, 2008 at 3:02 am.
Reply With Quote  
Join Date: Jun 2007
Posts: 51
Reputation: naju is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
naju's Avatar
naju naju is offline Offline
Junior Poster in Training

Re: How can i confirm a fucntion is exec once

  #5  
Mar 19th, 2008


ok let me little clearly state my problem much in detail

there are 50 file that each contains display() function at-least at 10 diff places.


display function is in display.php (included by all 50 files)

now i need single execution of certain contains of display()..... i cant make conditions while calling the function .... i need to do some thing in common inside that function ...


Thanks for follow up ...
i know ... this could be done
through static var or globals or include_once
but i dont know y all of these are not working with me this time ....

i m little bg ... i will specify the code ...
i know somewhere i got mistake ... but i m not getting for identifying it ...
thank you once again
Hunters Never Hurt
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Other Threads in the PHP Forum

All times are GMT -4. The time now is 3:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC