Old 20-07-2005, 10:36   #1 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Change content with link. How?

My PHP knowledge is very limited, so please help.
I have a simple website done with some PHP (that is require_once, as that's pretty much all that I know).

My problem is that I have to create an English version as well so I need to be able to change somehow the content of the page with a link, without leaving that page. That is if I am on the some-page.php page and want to switch to the English version I don't have to go back to the index_en.php page but still remain on some-page.php?somePHPmumboJumbo-content=en

Help.
  Reply With Quote
Old 20-07-2005, 10:52   #2 (permalink)
Joewebber
Senior Member
 
Joewebber's Avatar
 
Join Date: Feb 2004
Location: Exeter
Posts: 773
In its simplest form:


Code:
<?php $content = $_GET['content']; if ($content == "off") { echo "<a href=\"somepage.php?content=on\">Change content</a>\n"; } else if ($content == "on") { echo "<a href=\"somepage.php?content=off\">Change content back</a>\n"; }
  Reply With Quote
Old 20-07-2005, 10:57   #3 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Thanks. I really don't unserstand much of that, like how do I tell the script which content to load, and how do I associate $content with the actual content (I told you I knew nothing ) but it gives me a starting point.
Thanks again, Joe
  Reply With Quote
Old 20-07-2005, 11:00   #4 (permalink)
Joewebber
Senior Member
 
Joewebber's Avatar
 
Join Date: Feb 2004
Location: Exeter
Posts: 773
Quote:
Originally Posted by emilpaun
Thanks. I really don't unserstand much of that, like how do I tell the script which content to load, and how do I associate $content with the actual content (I told you I knew nothing ) but it gives me a starting point.
Thanks again, Joe

Thats what its doing, telling the browser which content to load, based on the link that has been clicked. $content is just a variable that stores the "on/off" state. Just put your relevant content inside the if statement.

Code:
if ($content == "off") { Put your first lot of content in here } else if ($content == "on") { Put your alternative content in here }
  Reply With Quote
Old 20-07-2005, 11:03   #5 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
I see. (I think) I'll try it out to see if I can make it work.
Thanks, Joe
  Reply With Quote
Old 20-07-2005, 11:06   #6 (permalink)
Transmogrify
Rough Creep Arse™
 
Transmogrify's Avatar
 
Join Date: Jul 2005
Location: Vancouver, Canada
Posts: 1,888
Send a message via MSN to Transmogrify
$content is a variable that stores the value of parameter passed in the URL - blah.php?content=off. So you can then use this to display one language content or another

So like -

with your url, some-page.php?somePHPmumboJumbo-content=en

Code:
$content = $_GET['somePHPmumboJumbo-content']; if ($content == "en") {
echo "Blah blah blah blah blah. You're nicked my son."
else if ($content == "fr") {
echo "Le blah le blah le blah. Vous etes arretes, mon fils!"
}
  Reply With Quote
Old 20-07-2005, 11:43   #7 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Thanks I reckon it'd be easier if i asked any of the programmers at work to do it for me, but I guess I'll never learn that way, huh?
I'm still struggling with it at the moment...
My current problem is, once the default content is loaded, do I need to refresh the page to change the main content? If so, how do I do this wizardry?
  Reply With Quote
Old 20-07-2005, 11:59   #8 (permalink)
Transmogrify
Rough Creep Arse™
 
Transmogrify's Avatar
 
Join Date: Jul 2005
Location: Vancouver, Canada
Posts: 1,888
Send a message via MSN to Transmogrify
Yes, you would. But then, the user would click on a link - language: <a href="some-page.php?somePHPmumboJumbo-content=en">english</a> | < href="some-page.php?somePHPmumboJumbo-content=fr">french</a>

or a drop down menu with an onchange="submit()" kind of thing going on.
  Reply With Quote
Old 20-07-2005, 12:06   #9 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Oookeeey... I was thinking of showing only one link on the page. That is<a href="whatever.php"> English</a> to appear on pages with Romanian content and viceversa...
Well I'm off to home now, I'll battle with it more, tomorrow.

Thanks again, guys
  Reply With Quote
Old 20-07-2005, 12:48   #10 (permalink)
Joewebber
Senior Member
 
Joewebber's Avatar
 
Join Date: Feb 2004
Location: Exeter
Posts: 773
Quote:
Originally Posted by emilpaun
Oookeeey... I was thinking of showing only one link on the page. That is<a href="whatever.php"> English</a> to appear on pages with Romanian content and viceversa...

You can do that with the method that I showed you.
Sorry, I don't know how to explain it any simpler (not supposed to sound patronising)
  Reply With Quote
Old 20-07-2005, 13:13   #11 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Don't worry, Joe. That did not sound patronisng at all. It's my fault I'm stupid.
I'm using your method, yet when I click on change content, nothing happens... I just need to read some more to find out what I'm doing wrong
  Reply With Quote
Old 22-07-2005, 01:02   #12 (permalink)
illvibe
say werd.
 
illvibe's Avatar
 
Join Date: Oct 2004
Location: Japan
Posts: 1,297
Basically I'm saying the same thing as Joe and Transmogrify, but hey...

The point is you're loading the same page, but changing the variable (and thus the content) with the link.

whatever.php might be the default page.
If you include a link on this page to whatever.php?language=en and it's clicked, you'll be loading the same page, but also including whatever content you've written in the if statement ie:

Code:
if ($language == "en") { Hello... } else if ($language == "fr") { Bonjour... }

So when you reload whatever.php as whatever.php?language=en, "Hello..." will be displayed. If you provide a link <a href="whatever.php?language=fr>Change to French</a>, then when a user clicks that link the page will be reloaded, the variable language will equal 'fr' (which is french) and thus "Bonjour..." will be displayed.

Comprendre?
  Reply With Quote
Old 22-07-2005, 03:13   #13 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Thanks, I understood so far. I need to find a way to implement it in my actual system of includes, whithout going through too much trouble. (I'm tackling this thing the lazy way, I know )
I'll keep you guys posted on my failures

Thank you very much for all the help
  Reply With Quote
Old 22-07-2005, 07:48   #14 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Allright me again
Can I echo an include?
I mean something like this:
Code:
echo "@ require_once ("file.php");";
You get the point
  Reply With Quote
Old 22-07-2005, 09:25   #15 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Ok so it's impossible...
So, how about this?
PHP Code:
$content_en "include (file.php); 
Or something similar?

Anyone?
  Reply With Quote
Old 22-07-2005, 09:44   #16 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Okey, more details

PHP Code:
-----------------------------------------------------------------------------------------
<?php
                       $page 
"php";
                       
$content_en "english content";
                       
$content_ro "continut romana";
?>
-----------------------------------------------------------------------------------------

These variables are defined in the top of the page
In the div with the switching content I put this

PHP Code:
-----------------------------------------------------------------------------------------
<div>
<?php

               
if ($content == "en") {
                       echo 
$content_en;
               }

               else if (
$content == "ro") {
                       echo 
$content_ro;
               }

?>
</div>
-----------------------------------------------------------------------------------------

What I'd like to know is if there is a way to have those variables include some files which I already created. That's why I don't want to put everything in this page...

Another question would be how do I go about including some default text. I mean if I enter in the browser instead of page.php?content=en just page.php nothing loads up (obviously)

Thanks
  Reply With Quote
Old 22-07-2005, 10:16   #17 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Quote:
Originally Posted by emilpaun

Another question would be how do I go about including some default text. I mean if I enter in the browser instead of page.php?content=en just page.php nothing loads up (obviously)


fixed. added an else statement, after the else if one.
still working on the other problem I mentioned
  Reply With Quote
Old 22-07-2005, 15:42   #18 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
ok. problem solved. thanks
  Reply With Quote
Old 23-07-2005, 20:11   #19 (permalink)
Outsourced
Registered User
 
Join Date: Jul 2005
Location: Staffordshire, England
Posts: 24
I've built a nice little tool... if u go on my web site http://www.outsourcedstudios.com and pop me an email, i'll send you a copy... uses PHP btw.

I cant put it here as its multiple pages (very simple tho).

=D
  Reply With Quote
Old 24-07-2005, 04:37   #20 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 7,588
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
Thanks, I appreciate it. There are 25 programmers in our firm and it would have been extremely easy for them to do this thing for me, but that way, I'd never learn
Thanks again
  Reply With Quote
Reply



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

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8