Jump to content

Recommended Posts

My language table structure looks like :

 

id | english

mail_accepted | Your e-mail is accepted.

thank_you | Thank you for your visit.

 

 

What I want to do is, I want to take all these data to an array like : "lang" array

And I can use these in the page like

<?php
echo "goodbye ".$lang['thank_you'];
?>

 

I know how to take data, lets say

<?php
$query = "select * from language.. ";
mysql_query($query);
?>

But then ?, which function should I use to take the data to my "$lang" array ?

Link to comment
https://forums.phpfreaks.com/topic/220150-from-mysql-to-an-array-how/
Share on other sites

$lang = array();
$rs = mysql_query('SELECT id, english FROM lang');
while ( $row = mysql_fetch_array($rs) )
{
  $lang[$row['id']] = $row['english'];
}

Add debugging and whatnot, but that's the structure.

 

Also, your table design is wrong, you should make 3 columns:  id, language, text.  This way, you can add a new language without adding columns.

 

-Dan

Also, your table design is wrong, you should make 3 columns:  id, language, text.  This way, you can add a new language without adding columns.

 

-Dan

Actually my table looks like :

id | english | german | swedish .. etc.

I m able to add more columns and languages,I did not understand why its wrong ?

 

select id,english from language

select id,german from language

select id,swedish from language

etc..

 

Because you have to alter the table (which takes a long time) every time you have to add a new language.

 

If you designed it my way, you can say:

SELECT id, text FROM lang WHERE language = 'swedish';

 

You could also have a second table holding id/value pairs for the languages so you can say:

SELECT id, test FROM lang WHERE language = 3;

 

If you continue down your path, you will have to add a new column for every new language, which will lock the table (and prevent your site from working while the operation completes).

 

-Dan

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.