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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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