Jump to content

More than one result


Waxxy

Recommended Posts

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

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

 

 

<?
        $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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.