teerock Posted February 6, 2007 Share Posted February 6, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/37280-translate-quote-of-day/ Share on other sites More sharing options...
xec Posted February 17, 2007 Share Posted February 17, 2007 Hii, u will have to use a third party to convert whatever english sentence in to spanish ... Mysql does not support such type of things... Quote Link to comment https://forums.phpfreaks.com/topic/37280-translate-quote-of-day/#findComment-186959 Share on other sites More sharing options...
teerock Posted February 19, 2007 Author Share Posted February 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/37280-translate-quote-of-day/#findComment-188276 Share on other sites More sharing options...
bennyboywonder Posted March 1, 2007 Share Posted March 1, 2007 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/37280-translate-quote-of-day/#findComment-196746 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.