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>'; } ?> Link to comment https://forums.phpfreaks.com/topic/96023-more-than-one-result/ 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. Link to comment https://forums.phpfreaks.com/topic/96023-more-than-one-result/#findComment-491584 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 Link to comment https://forums.phpfreaks.com/topic/96023-more-than-one-result/#findComment-491601 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* Link to comment https://forums.phpfreaks.com/topic/96023-more-than-one-result/#findComment-491613 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>'; } ?> Link to comment https://forums.phpfreaks.com/topic/96023-more-than-one-result/#findComment-491618 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. Link to comment https://forums.phpfreaks.com/topic/96023-more-than-one-result/#findComment-491621 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. Link to comment https://forums.phpfreaks.com/topic/96023-more-than-one-result/#findComment-491623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.