massimoGornatti Posted May 2, 2007 Share Posted May 2, 2007 hey guys, ok so I'm creating a blog-type site for my family. And many of my relatives live in Argentina. So I wanted to post messages both in english and spanish. Maybe have a language selector up on top of the blog so that people can choose. But I don't want to have two pages for each language version. I would like to just have one and call which language is being used. I've seen this as part of the URL: index.php?language=en that's what I want. How do they do that? do I have to enclose each post with div tags? can anyone help me? thanks!!! Link to comment https://forums.phpfreaks.com/topic/49726-indexphplanguageen/ Share on other sites More sharing options...
Moon-Man.net Posted May 3, 2007 Share Posted May 3, 2007 you will need to use the $_GET[] array, read up on it <a href='http://www.w3schools.com/php/php_get.asp'>HERE</a> to access that variable you would use echo $_GET['language'] and it would print what ever proceeds the = sign in the URL. Now as for the actual language, I would have no idea how you are going to do that. Include a different page maybe? -- Nathan Link to comment https://forums.phpfreaks.com/topic/49726-indexphplanguageen/#findComment-243905 Share on other sites More sharing options...
corbin Posted May 3, 2007 Share Posted May 3, 2007 I'm assuming your blog will be based around a SQL database. The best way to do it would be when ever you make posts, have a select box for selecting language. Then when you insert the stuff into the database, just have English as 0 and Spanish as 1 or something. Then, based on the $_GET['language'] you could query the DB in different ways.... For example, the page that shows the post could look something like: //assume the db conn is already made if($_COOKIE['language'] == "es" || $_GET['language'] == "es") { //if a cookie value or a $_GET value is set for Spanish, then set $language to 1... You may also want to set a cookie under here, so people's language could be remembered. (hence he cookie check in the if ) $language = 1; } else { $language = 0; } $q = mysql_query("SELECT * FROM posts WHERE lang = '{$language}' ORDER BY post_time DESC LIMIT 0,5"); //this assumes your database is set up to have a lang column for language (0 for English, 1 for Spanish) and that post_time is a column in which the time the post was made is stored. while($r = mysql_fetch_assoc($q)) { //echo out each post and what not ;p } Link to comment https://forums.phpfreaks.com/topic/49726-indexphplanguageen/#findComment-243923 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.