Jump to content

php/mysql result from two tables


grigori

Recommended Posts

Hello everyone :) I'm George(Giorgos in greek), and i'm 16, these are my first steps in coding, since i am learning everything from beginning, so don't be rough to me :):)

 

To the point now, i have some script examples, which i'm using only for learning purpose on localhost. The thing is that i'm trying to make an english-greek dictionary, using ajax/mysql/php, but just with small amount of words...

I have managed to work but only with one table, and there are two tables, one for eng-gr, and another one for gr-eng translation. So my question is, how can i get translation, according to language i type in field, without previously selecting  relation between languages.

db=test,

table1, has 3 columns: id, eng, gr

table2, also 3 columns: id, gr, eng

 

and the script:

 
<?php 

$db_host="test";
$db_name="test";
$username="1234";
$password="1234";


$db_con=mysql_connect($db_host,$username,$password);
$connection_string=mysql_select_db($db_name);
mysql_connect($db_host,$username,$password);
mysql_select_db($db_name);
mysql_query("SET NAMES 'utf8'"); 


?>
<?php
$searchq		=	strip_tags($_GET['q']);
$getRecord_sql	=	'SELECT * FROM `test` WHERE `eng` LIKE "'.$searchq.'%"';
$getRecord		=	mysql_query($getRecord_sql);
if(strlen($searchq)>0){


echo '<ul>';
while ($row = mysql_fetch_array($getRecord)) {?>
	<li><a href="#"><?php echo $row['eng']; ?> <small><?php echo $row['gr']; ?></small></a></li>
<?php } 
echo '</ul>';
?>
<?php } ?>

 

Thank you in advance

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.