Author |
Message |
hinksta
Worker


Joined: Dec 23, 2005
Posts: 226
Location: UK
|
Posted:
Sat Dec 02, 2006 8:19 pm |
|
I have a module index.php that has two parts. If I put the module in the home I only want the first part to run. So I need to make the second part into a function, this I think I'm ok with, what I don’t know is how to have the function run at other times.
Or is there another way to do this say with a function for the home page only.
Could someone point me in the right direction? |
|
|
|
 |
Guardian2003
Site Admin

Joined: Aug 28, 2003
Posts: 6799
Location: Ha Noi, Viet Nam
|
Posted:
Sat Dec 02, 2006 9:43 pm |
|
So you have two routines on the same index file. When the module is set to 'home' you only want the first routine to execute but when its not in 'home' you want both to execute?
Are there any other considerations - for example are you trying to limit the second one to run only if its an admin or..... |
|
|
|
 |
hinksta

|
Posted:
Sun Dec 03, 2006 6:39 am |
|
Yes that's exactly it.
I may need to add admin features in the future but not at the moment. |
|
|
|
 |
montego
Site Admin

Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Sun Dec 03, 2006 8:34 am |
|
Well, I am still unclear. If your module is NOT "In Home", should it do something different?
If you need to know if your module is "in Home", you could have it check the nuke_main table. This would allow your index.php to call two different functions depending upon whether the module is "in Home" or not. |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
 |
hinksta

|
Posted:
Sun Dec 03, 2006 8:49 am |
|
Quote: | Well, I am still unclear. If your module is NOT "In Home", should it do something different? |
If it is in home it should run only function 1.
If it is not in home it should run both functions.
Quote: | If you need to know if your module is "in Home", you could have it check the nuke_main table. This would allow your index.php to call two different functions depending upon whether the module is "in Home" or not. |
So if in nuke_main run function1
else run function1 + function2 |
|
|
|
 |
montego

|
Posted:
Sun Dec 03, 2006 9:13 am |
|
Quote: |
So if in nuke_main run function1
else run function1 + function2
|
Yup. |
|
|
|
 |
hinksta

|
Posted:
Sun Dec 03, 2006 9:53 am |
|
Code:$row = $db->sql_fetchrow($db->sql_query("SELECT main_module FROM ".$prefix."_main WHERE title='MySearch'"));
if ($row["MySearch"]) {
home
} else {
home,nothome
)
|
Am I heading in the right direction? |
|
|
|
 |
montego

|
Posted:
Sun Dec 03, 2006 10:05 am |
|
something more like this:
Code:
$row = $db->sql_fetchrow($db->sql_query("SELECT main_module FROM ".$prefix."_main LIMIT 1"));
if ($row['main_module'] == "MySearch") {
home
} else {
home,nothome
}
|
|
|
|
|
 |
hinksta

|
Posted:
Sun Dec 03, 2006 10:22 am |
|
I'm getting a blank page so far
is the right way to make a function?
Code:function home(){
global $db, $prefix;
function code goes here
}
|
|
|
|
|
 |
hinksta

|
Posted:
Sun Dec 03, 2006 10:50 am |
|
Got it working ok in the home but something is wrong when I add the ELSE
Code:$row = $db->sql_fetchrow($db->sql_query("SELECT main_module FROM ".$prefix."_main LIMIT 1"));
if ($row['main_module'] == "MySearch") {
home();
} else {
home(), nothome();
}
|
|
|
|
|
 |
montego

|
Posted:
Sun Dec 03, 2006 11:01 am |
|
wrong syntax. He must be:
home();
nothome(); |
|
|
|
 |
hinksta

|
Posted:
Sun Dec 03, 2006 12:03 pm |
|
that's great thank you very much.
for some reason the second function doesn't run so I may have to make some changes. maybe the functions are a bit mixed up. |
|
|
|
 |
hinksta

|
Posted:
Sun Dec 03, 2006 1:06 pm |
|
The first function 'home' runs ok but the second function 'nothome' does not run.
I also tried to run both functions in the home but 'nothome' still failed.
is something missing or should I have a closer look at the function?
Code:$row = $db->sql_fetchrow($db->sql_query("SELECT main_module FROM ".$prefix."_main LIMIT 1"));
if ($row['main_module'] == "MySearch")
{
home();
}
else
{
home();
nothome();
}
|
|
|
|
|
 |
hinksta

|
Posted:
Sun Dec 03, 2006 2:19 pm |
|
I think i'm getting a bit closer.
using the if else statment tells it only to run the function 'home' if MySearch is in nuke_main.
if i am browsing on another page it still only run's 'home' because MySearch is still in nuke_main |
|
|
|
 |
hinksta

|
Posted:
Sun Dec 03, 2006 3:05 pm |
|
When reading back on this thread i see that i may have misled you a bit
What I meant by "when not in home" was, when you browse away from the home page to another page of the module itself. |
|
|
|
 |
hinksta

|
Posted:
Sun Dec 03, 2006 4:54 pm |
|
What was I thinking
I just made a block out of the first function, sorted.
Well thanks for your help Montego, I learnt how to run a function today.  |
|
|
|
 |
montego

|
Posted:
Sun Dec 03, 2006 5:58 pm |
|
|
|
 |
|