|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
ok well i am writing a script where, for example, a user clicks a link that is the following
"http://www.mydomain.com/home.php?loc=test", the page will display the template provided in home.php but in the body field of home.php is the variable $content...and that variable is set with the following function: PHP Code:
hopefully that is clear enough but im obviously doing something wrong..so what is it? and everything is working fine BUT i get tWO instances of the function...i get one that is displayed at the VERY top of the page above everything else and one that is where it should be...i use the switch conditional like so: PHP Code:
and i echo the $content var out in the body of the page (where it should be displayed) with PHP Code:
thanks in advance
__________________
-Alexander Last edited by Vasarab69 : December 27th, 2002 at 09:41 PM. |
|
#2
|
|||
|
|||
|
Are you register_globals on or off? You should try using the $_GET[] superglobal to retrieve the value being passed from the URL...
Also, in your content() function, you should return the value that you want your $content variable to hold.
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#3
|
|||
|
|||
|
register_globals are off...and ill try that now and get back to the board with the info
|
|
#4
|
|||
|
|||
|
im not sure but i think the problem lies when i set the variable...how do i tell a variable to execute a function when its called? for example, i how do i tell the variable $content to call the function content() when its called...im using
$content = content(); echo $content; and the function content() includes a specific file which depends on the variable (it would include the file 'test.php' if the address was ../home.php?loc=test) and i am using the $_GET superglobal to retrieve the value of the "loc" variable...this time ive provided the complete code . . . |
|
#5
|
|||
|
|||
|
Quote:
Well, that's fine... But in your content() function, you need to return a value that will be stored in your $content variable: PHP Code:
|
|
#6
|
|||
|
|||
|
the value of $content is the actual page to which the variable is referring...
for example, if the browser points to "../home.php?loc=test" then im trying to, basically, grab the file 'test.php' and include in the body of the page using the variable $content...which means im assigning the actual page 'test.php' as the value of content...and test.php contains nothing more than text, so really it could be "test.txt" or any other extension as long as i can insert it into the body of home.php . . . i hope i'm making sense though |
|
#7
|
|||
|
|||
|
Okay... I get what you're trying to do...
Try this then: PHP Code:
And when calling it... try this: $content = content(); include ($content); HTH! |
|
#8
|
|||
|
|||
|
works like a charm! thanks a lot FrankieShakes! jeez u should write an article on this lol
|
|
#9
|
|||
|
|||
|
No problem... Any time!
Hehehe... I might just do that! ![]() |
|
#10
|
|||
|
|||
|
now all that is working but ive encountered a new feature i'd like to add...can i assign a variable as a case? so this way i wont have to make a case for every value of the $loc variable, i would just have to make the file...
with the above code at hand, couldnt i make: PHP Code:
i could, but its not working..when i use this code it just executes the 'default' case and not the one i'm trying to access . . . any workarounds? Last edited by Vasarab69 : December 28th, 2002 at 01:15 PM. |
|
#11
|
|||
|
|||
|
or is that not possible?
thanks-- |
|
#12
|
|||
|
|||
|
I'm not sure if I understand what you mean... In your switch/case statements, you'll need to compare each "case" with the value that's being passed from the link:
ex: loc=home loc=contact, etc... |
|
#13
|
|||
|
|||
|
right...but isnt there a way to dynamically create a case (not permanently, just on-the-fly) and refer it to an already existing page (this way it would save a lot of time)...
i was thinking something along the lines of this would work: PHP Code:
(since $loc was extracted from the web address using superglobal $_GET[loc]) and remember, the function that is above this in the "source file" defines what file should be included depending on what the value of 'loc' is in the address, or else it just includes the main file (index.php; which is included via the 'default' case in the switch) if it replaced that replaced the switch variable i previously posted it should work i think but it doesnt, so im not sure what is wrong? also, since that DOES replace the 'old' switch conditional i posted previously, in the code, i kept the 'default' case of course... sorry for wasting so much of your time FrankieShakes but you've played a very big rrole in helping me find my inner-web developer ![]() Last edited by Vasarab69 : December 28th, 2002 at 06:25 PM. |
|
#14
|
|||
|
|||
|
Okay, I think I understand what you mean now... What you'll need to do then is pass the value of $loc to the content() function like so: PHP Code:
|