Waxxy Posted March 13, 2008 Share Posted March 13, 2008 Hi, ive built a translation tool from english into russian. Hosted my database in sql, but so far it only accepts translations word for word. What do i need to do for it to allow a string of words translated? Thank you <? $trans = $_POST["translate"]; include("connection.php"); $connection = @mysql_connect($db_host, $db_user, $db_password) or die("Error Connecting"); mysql_select_db($db_name, $connection); mysql_query("set character_set_results='utf8'"); mysql_query("set NAMES utf8"); mysql_query("SET CHARACTER SET utf8"); mysql_query("set character_set_client='utf8'"); $query = "select* FROM Dictionary where english ='$trans'"; $result= mysql_query($query, $connection); $num_rows = mysql_num_rows($result); for ($i =0; $i< mysql_num_rows($result); $i++) { $english = mysql_result($result, $i, "english"); $russian = mysql_result($result, $i, "russian"); echo '<tr> <td width="550" height="30"align="center" valign="middle"><a href="'.$english.'?page=">'.$english.'/'.$russian.'</a></td> </tr>'; } ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted March 13, 2008 Share Posted March 13, 2008 $trans = explode(" ",$_POST["translate"]); Then just cycle through each word and translate. Quote Link to comment Share on other sites More sharing options...
Waxxy Posted March 13, 2008 Author Share Posted March 13, 2008 $trans = explode(" ",$_POST["translate"]); Then just cycle through each word and translate. that still outputs as word for word Quote Link to comment Share on other sites More sharing options...
papaface Posted March 13, 2008 Share Posted March 13, 2008 Show us your new code. You need to do something like this with your code: $trans = explode(" ",$_POST["translate"]); foreach ($trans as $word) { $select = mysql_query("SELECT `russianword` from `words` where `englishword`=".$word." "); list ($w) = mysql_fetch_array($select); $string .= " " . $w; } $string = trim($string," "); echo $string; *code not tested* Quote Link to comment Share on other sites More sharing options...
Waxxy Posted March 13, 2008 Author Share Posted March 13, 2008 <? $trans = $_POST["translate"]; include("connection.php"); $connection = @mysql_connect($db_host, $db_user, $db_password) or die("Error Connecting"); mysql_select_db($db_name, $connection); mysql_query("set character_set_results='utf8'"); mysql_query("set NAMES utf8"); mysql_query("SET CHARACTER SET utf8"); mysql_query("set character_set_client='utf8'"); $query = "select* FROM Dictionary where english ='$trans'"; $trans = explode(" ",$_POST["translate"]); $result= mysql_query($query, $connection); $num_rows = mysql_num_rows($result); for ($i =0; $i< mysql_num_rows($result); $i++) { $english = mysql_result($result, $i, "english"); $russian = mysql_result($result, $i, "russian"); echo '<tr> <td width="550" height="30"align="center" valign="middle"><a href="'.$english.'?page=">'.$english.'/'.$russian.'</a></td> </tr>'; } ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted March 13, 2008 Share Posted March 13, 2008 Your code will not work as you're not cycling through. See my example. We're here to help, not code entire scripts. Quote Link to comment Share on other sites More sharing options...
Waxxy Posted March 13, 2008 Author Share Posted March 13, 2008 oh thats what you meant, sorry been at this for a while now, got lost in the process of everything. Quote Link to comment 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.