dictionary translation linked to translation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

dictionary translation linked to translation

Post by spamyboy »

I have two dictionary databases:
1.) lithuanian - english
2.) english - lithuanian
I need for e.g. if I see some translation "lithuanian - english":
`labas - hello, greeting word`
to check if there arent some words from explanation avayble in "english - lithuanian" dictonary if there is:
`labas - <a href="#word_id">hello</a>, greeting <a href="#word_id">word</a>`.
Here is how do I display curent word:

Code: Select all

$mysql_db = new MySQL ("localhost", "root", "***", "dictionary");
$result = $mysql_db->query ("SELECT * FROM anglulietuviu WHERE id=$word_id");
$row = mysql_fetch_array($result);
echo "<strong>Word</strong> ".$row['word']."<br />";
echo "<strong>Translation</strong> <span id=\"".$row['id']."\">".$row['translation']."</span><br />";
and dabase structure is wery simple:
anglulietuviu:

Code: Select all

id, word, traslation
lietuviuanglu:

Code: Select all

id, word, traslation
-------------------------------------------------------

I think we are talking about day and night. I will try to explain once again my problem. I have two tables in my database: terms_engtolt (id, term, translation), terms_lttoeng (id, term, translation). I need that when client is viewing translation from terms_engtolt, every word of it (each word from translation) would be checked for TERM matches from terms_ltoeng if there are any matches word from translation should be replaced to link to the translatio for the matched term.
Do you understand now ?
Last edited by spamyboy on Sat Oct 13, 2007 2:52 am, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

:roll:

Code: Select all

<?php
$result = $mysql_db->query ("SELECT * FROM anglulietuviu WHERE word in ('" . implode("', '", array_map('mysql_real_escape_string', array_unique(array('hello', 'i', 'am', 'astions')))) . "')");
$row = mysql_fetch_array($result);
?
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

I don't see how this might help...
I'm more thinking of somthing like exploding result and using simple WHERE query for every explodet string if there is match basicly add link with ID to it.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

spamyboy wrote:I don't see how this might help...
I'm more thinking of somthing like exploding result and using simple WHERE query for every explodet string if there is match basicly add link with ID to it.
Why would you want multiple queries when you could have 1?

astions' script addresses the IN() portion of the query with implode(), the security of the data with array_map(), and the lack of duplicate words with array_unique(). If you wrote it yourself, it'd have likely been easier to understand. The array that he gave as an example is meant to be an array of every word you are after (explode()? :P).

If you really want to use up a lot of resources though, go ahead and query every single word.
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

Ok, I'm lost, I don't have any idea of how to use His example.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

spamyboy wrote:Ok, I'm lost, I don't have any idea of how to use His example.
I heard you the first time. Then, I explained it to you. Now, make sense out of the explanation. Look at all of the MySQL/PHP functions that I mentioned, and make sense out of it instead of always asking us to spoon feed you.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

That query will return the id's for an array of words..

ie (pseudo)

Code: Select all

while ($data = mysql_fetch_assoc())
{
    echo "The id for word {$data['word']} is {$data['id']}<br />";
}
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


It seems that I'm still confused about it. Now I use it like:

Code: Select all

$query = $dSystem->db->query("SELECT term, translation FROM terms_engtolt ORDER BY RAND() LIMIT 10");
while($row=$dSystem->db->fetch_array($query)){
print_r(print_r($row)."<br />");
}
And I get my results for e.x.

Code: Select all

Array ( [id] => 618 [term] => am [translation] => , esam. laiko vienask. 1 asmuo iš to be. )
but that is translation from english to lithuanian, now I need to search for every word from translation in other database terms row and if there is such match replace curent word from curent english-lithuanian translation to a link to other database liethuanian-english.
I think you should understand.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

still nothing, pleas.
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

I think we are talking about day and night. I will try to explain once again my problem. I have two tables in my database: terms_engtolt (id, term, translation), terms_lttoeng (id, term, translation). I need that when client is viewing translation from terms_engtolt, every word of it (each word from translation) would be checked for TERM matches from terms_ltoeng if there are any matches word from translation should be replaced to link to the translatio for the matched term.
Do you understand now ?
Post Reply