Rommeo Posted November 29, 2010 Share Posted November 29, 2010 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 More sharing options...
ManiacDan Posted November 29, 2010 Share Posted November 29, 2010 $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 Link to comment https://forums.phpfreaks.com/topic/220150-from-mysql-to-an-array-how/#findComment-1140980 Share on other sites More sharing options...
Rommeo Posted November 29, 2010 Author Share Posted November 29, 2010 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.. Link to comment https://forums.phpfreaks.com/topic/220150-from-mysql-to-an-array-how/#findComment-1140983 Share on other sites More sharing options...
ManiacDan Posted November 29, 2010 Share Posted November 29, 2010 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 Link to comment https://forums.phpfreaks.com/topic/220150-from-mysql-to-an-array-how/#findComment-1140986 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.