Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 07-26-2007, 11:22 AM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP $_GET help please (a bit of a newbie question)

Hey guys, I'm just getting into PHP and have started on a site for someone, it will be dual language, and this is what I have so far:

PHP Code:
<?php
if(isset($_GET['lang']))
if(
$lang == "en")   {   ?>
        <div align="center">
          <p align="justify">English Text</p>
        </div> </div>
<?php 
    
}      
else if(
$lang == "nl")
          { 
?>
                <div align="center">
                  <p align="justify">Dutch Text</p>
    </div></div>
<?php ?>
Now, I'm using index.php?lang=en or lang=nl for each one, but I can figure out where I'm going wrong - when the page loads there is no text, I want it to default to Dutch - how do I achieve this? I thought I knew how but it wouldn't work.

Is there any other easier way of achieveing this as well? I thought this was the easiest way I could find.

Cheers

Jason
Reply With Quote
  #2  
Old 07-26-2007, 11:40 AM
nexialys
Guest
 
Posts: n/a
Default

actually, $_GET['lang'] goes nowhere, as you call for a different variable afterward: $lang...

use $_GET['lang'] everywhere...
Reply With Quote
  #3  
Old 07-26-2007, 11:44 AM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Strangely enough - when I go down that road - it no longer works, but as my code above - that works fine ... any suggestions?

Cheers

[edit] I removed the == and replaced with just one - I've put two in and it's fine now, but I still need to figure out how to default it to Dutch (when there is no ?lang=nl placed at the end of the script)
Reply With Quote
  #4  
Old 07-26-2007, 11:51 AM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
<?php
if (!isset($_GET'lang']))
{
    
$lang 'nl';
}
else
{
    
$lang =& $_GET['lang'];
}

if (
$lang == 'en')
{
    
?>
    <div align="center">
    <p align="justify">English Text</p>
    </div>
    <?php 
}      
else
{
    
?>
    <div align="center">
    <p align="justify">Dutch Text</p>
    </div>
    <?php
}
?>
This defaults to nl if lang is not set or anything other than en.
Anyway, mixing code and data is no good practice!

I'd suggest to use a template engine.
Reply With Quote
  #5  
Old 07-26-2007, 11:57 AM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Andreas View Post
I'd suggest to use a template engine.
Store everything in a MySQL database and pull it out that way? That was an option but for a simple site, I thought it was just easier to pull it out of each page (plus it would share my Forum database which often has too many connections).

Thanks for your help - I understand it better now.

Jason
Reply With Quote
  #6  
Old 07-26-2007, 12:03 PM
Andreas's Avatar
Andreas Andreas is offline
 
Join Date: Jan 2004
Location: Germany
Posts: 6,863
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Store everything in a MySQL database and pull it out that way?
Not necessarily.

You might want to take a look at Smarty.
Reply With Quote
  #7  
Old 07-26-2007, 12:46 PM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Installed and experimenting - thanks guys, your help is very much appreciated

Jason
Reply With Quote
Reply

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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:04 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03985 seconds
  • Memory Usage 2,217KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (6)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete