Jump to content

Recommended Posts

Hi fellow scripters,

 

I'm new to this and have an application that requires me to display a quote of the day on a website (randomly picked from a MySQL table) in spanish and then translate it to the equivalent quote in english when the user clicks on it.

 

Any help would be much appreciated.

 

Cheers,

Teerock

Link to comment
https://forums.phpfreaks.com/topic/37280-translate-quote-of-day/
Share on other sites

  • 2 weeks later...

Hi Xec,

 

thanks for your response. I'm planning on having the quote already translated and entered into a table, once in spanish and once in english. When the user clicks on the quote in spanish I need the script to look up the corresponding english quote in the table and return it. Is this possible?

 

Remember I am very new at php and MySQL.

 

Regards,

 

Teerock

  • 2 weeks later...

The following script should echo a hyperlink containing a random quote looked up from a table on your database named translate (obviously you can call it what you want, as with the column names as well) the table needs to have three columns, one english (named english in my script) one spanish (named spanish in my script) and one auto incrementing primary key (named qId in my script). When you click the link, the page should reload with the translation instead. Be aware that I havn't tested this, so if it doesn't work, tell me what it says...

 

<?php
$dbhost = "myhost";
$dbuser = "myuser";
$dbpass = "mypass";
$dbname = "mydbase";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to Mysql');
mysql_select_db($dbname) or die('cannot select database');
if(!$_GET) {                                                // If no variables have been passed to the script through the url
    $query = "SELECT COUNT(qId) AS count FROM translate";   // Set the query string to count how many entries
    $result = mysql_query($query);                          
    $row = mysql_fetch_row($result);
    $select = rand(1, $row['count']);                           // generate a random number between 1 and the count value created earlier
    $query = "SELECT english FROM translate WHERE qId=$select"; // this counts how many entries are in the database
    $result = mysql_query($query);
    $row = mysql_fetch_row($result);
    echo "<a href='" . $_SERVER['PHP_SELF'] . "?translate=$select'>" . $row[0] . "</a>";
} else {
    $query = "SELECT spanish FROM translate WHERE qId=$_GET['translate']";
    $result = mysql_query($query);
    $row = mysql_fetch_row($result);
    echo $row[0];
}
mysql_close($conn);
?>

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.