adamriley Posted July 25, 2010 Share Posted July 25, 2010 This is what I have so far... language.php <?php session_start(); $con = mysql_connect("sql09.freemysql.net","adamlr14",""); if (!$con) { die('Could not connect: ' . mysql_error()); } $language = 'en'; echo mysql_error(); mysql_select_db("language", $con); if(!mysql_select_db("language", $con)) { die('Could not select db: ' . mysql_error()); } $result = mysql_query("SELECT * FROM en"); $row = mysql_fetch_array($result); echo mysql_error(); ?> example of database ref text 1 Welcom this site is in construction! 2 Please login before you continue! Now the bit I want to do now is 'require' the page and echo for example $row[text] were $row[ref] = "1" Sorry if it is confusing Quote Link to comment https://forums.phpfreaks.com/topic/208853-how-can-this-be-done/ Share on other sites More sharing options...
wildteen88 Posted July 25, 2010 Share Posted July 25, 2010 Now the bit I want to do now is 'require' the page Require what page? NOTE: You may want to edit your post and remove your database credentials Quote Link to comment https://forums.phpfreaks.com/topic/208853-how-can-this-be-done/#findComment-1090975 Share on other sites More sharing options...
adamriley Posted July 25, 2010 Author Share Posted July 25, 2010 Now the bit I want to do now is 'require' the page Require what page? The aim of this file is to pull the 'text' from the database and the requiring page would show it example of the file requiring language.php adam.php <?php require("language.php"); echo {the bit I cannot do} {echo $row[text] were $row[ref] = 1 } ?> I would like it to echo Welcom this site is in construction! Quote Link to comment https://forums.phpfreaks.com/topic/208853-how-can-this-be-done/#findComment-1090977 Share on other sites More sharing options...
wildteen88 Posted July 25, 2010 Share Posted July 25, 2010 You'll need to use an MySQL query first. Really basic example $sql = 'SELECT text FROM en WHERE ref=1'; $result = mysql_query($sql); if($result) { list($lang_text) = mysql_fetch_row($result) echo "<b>$lang_text</b>"; } else { echo 'Cannot find language text'; } However you wouldn't want to do that for every bit of text you want to output. Instead you'll be better of getting all the text from the database first $sql = 'SELECT ref, text FROM en'; $result = mysql_query($sql); if($result) { while($row = mysql_fetch_row($result)) { list($id, $text) = mysql_fetch_row($result); $lang[$id] = $text; } } Now for each bit of text you want you'll just echo out the nesseccary variable ([ tt]echo $lang[ref id]; ), eg echo $lang[1] . '<br />' . $lang[2]; Quote Link to comment https://forums.phpfreaks.com/topic/208853-how-can-this-be-done/#findComment-1090984 Share on other sites More sharing options...
adamriley Posted July 26, 2010 Author Share Posted July 26, 2010 Now this is my code ... language.php <?php session_start(); $con = mysql_connect("sql09.freemysql.net","adamlr14",""); if (!$con) { die('Could not connect: ' . mysql_error()); } echo mysql_error(); mysql_select_db("language", $con); if(!mysql_select_db("language", $con)) { die('Could not select db: ' . mysql_error()); } $sql = 'SELECT ref, text FROM en'; $result = mysql_query($sql); if($result) { while($row = mysql_fetch_row($result)) { list($id, $text) = mysql_fetch_row($result); $lang[$id] = $text; } } print_r($lang); echo mysql_error(); ?> The problem is is that if you try to pull an odd number for example $lang[3] it echos nothing but if you change it to even number $lang[2] it echo what it should ....... I used print_r(lang) and it only has even numbers ??????? print_r($lang) Array ( [2] => try2 [4] => try4 [6] => try6 ) database ref text 1 try1 2 try2 3 try3 4 try4 5 try5 6 try6 Quote Link to comment https://forums.phpfreaks.com/topic/208853-how-can-this-be-done/#findComment-1091196 Share on other sites More sharing options...
adamriley Posted July 26, 2010 Author Share Posted July 26, 2010 anyone Quote Link to comment https://forums.phpfreaks.com/topic/208853-how-can-this-be-done/#findComment-1091229 Share on other sites More sharing options...
adamriley Posted July 26, 2010 Author Share Posted July 26, 2010 Bumpy Bumpy ???? Quote Link to comment https://forums.phpfreaks.com/topic/208853-how-can-this-be-done/#findComment-1091339 Share on other sites More sharing options...
wildteen88 Posted July 26, 2010 Share Posted July 26, 2010 Oops. I coded the while loop wrong. It should be like if($result) { while(list($id, $text) = mysql_fetch_row($result)) $lang[$id] = $text; } Quote Link to comment https://forums.phpfreaks.com/topic/208853-how-can-this-be-done/#findComment-1091361 Share on other sites More sharing options...
adamriley Posted July 26, 2010 Author Share Posted July 26, 2010 Thanks very much for your help Quote Link to comment https://forums.phpfreaks.com/topic/208853-how-can-this-be-done/#findComment-1091364 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.