Really really need help with this one!
I need to convert from php to mysql so that it reads language information from mysql, i made mysql table already but I just don't know how to change from php to mysql

<?php
session_start();
header('Cache-control: private');

if(isSet($_GET['lang']))
{
$lang = $_GET['lang'];

$_SESSION['lang'] = $lang;

setcookie("lang", $lang, time() + (3600 * 24 * 30));
}
else if(isSet($_SESSION['lang']))
{
$lang = $_SESSION['lang'];
}
else if(isSet($_COOKIE['lang']))
{
$lang = $_COOKIE['lang'];
}
else
{
$lang = 'en';
}

switch ($lang) {
  case 'en':
  $lang_file = 'lang.en.php';
  break;

  case 'de':
  $lang_file = 'lang.de.php';
  break;

  case 'es':
  $lang_file = 'lang.es.php';
  break;

  default:
  $lang_file = 'lang.en.php';

}

include_once 'languages/'.$lang_file;
?>

and my language file

<?php

$lang = array();

$lang['PAGE_TITLE'] = 'My website page title';
$lang['HEADER_TITLE'] = 'My website header title';
$lang['SITE_NAME'] = 'My Website';
$lang['SLOGAN'] = 'My slogan here';
$lang['HEADING'] = 'Heading';


$lang['MENU_HOME'] = 'Home';
$lang['MENU_ABOUT_US'] = 'About Us';
$lang['MENU_OUR_PRODUCTS'] = 'Our products';
$lang['MENU_CONTACT_US'] = 'Contact Us';
$lang['MENU_ADVERTISE'] = 'Advertise';
$lang['MENU_SITE_MAP'] = 'Site Map';
?>

My done mysql table, i need it to take data from mysql and display

CREATE TABLE IF NOT EXISTS `languages` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `short` varchar(2) NOT NULL,
  `name` varchar(32) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;

INSERT INTO `languages` (`id`, `short`, `name`) VALUES
(1, 'en', 'English'),

CREATE TABLE IF NOT EXISTS `translations` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `keyword` varchar(128) NOT NULL,
  `lang` int(10) unsigned NOT NULL,
  `value` varchar(256) NOT NULL,
  PRIMARY KEY (`id`,`lang`),
  KEY `keyword` (`keyword`),
  KEY `lang` (`lang`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=13 ;

INSERT INTO `translations` (`id`, `keyword`, `lang`, `value`) VALUES
(1, 'PAGE_TITLE', 1, 'My website page title'),
(2, 'HEADER_TITLE', 1, 'My website header title'),
(3, 'SITE_NAME', 1, 'My Website'),
(4, 'SLOGAN', 2, 'My slogan here'),
(7, 'HEADING', 3, 'Heading');

ALTER TABLE `translations`
  ADD CONSTRAINT `translations_ibfk_1` FOREIGN KEY (`lang`) REFERENCES `languages` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;

Any questions, just ask, really really need to get this one working

Member Avatar for diafol

You could try this:

function getTranslations($lang_id=1){
    $q=mysql_query("SELECT `keyword`,`value` FROM translations WHERE lang = $lang_id");
    while($d = mysql_fetch_array($q)){
        $k = $d['keyword'];
        $v = $d['value'];
        $l[$k] = $v;    
    }
    return $l;
}

$lang = getTranslations(2); //2 = German??
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.