How to get data from two different tables?

Asked

Viewed 449 times

-1

Guys I’m having a problem I’m making a site where I take the images of two different tables but I can only call one what I should do someone please can help me?

1 answer

0

You can do it this way:

SELECT * FROM tabela1 as t1
LEFT JOIN tabela2 as t2 USING(id)

This way, you take everything from the two tables, but you can also specify what you want to search for:

SELECT
   t1.imagem,
   t1.id,
   t2.imagem,
   t2.id
FROM tabela1 as t1
LEFT JOIN tabela2 as t2 USING(id)

In both cases, they would work... However, it is a little uncomfortable to elaborate an exact answer, based only on texts, and not on specific information from your database.

  • it is good to use Join to relate tables but I can never use it.see my code

  • <!-- Calling database data --> <? php session_start(); $email=$_SESSION['email']; $password=$_SESSION['password']; ? > <? php include '. /php/connection.php'; $result = mysql_query("SELECT * FROM user Where email = '$email' and password = '$password'") or dile(mysql_error()); $Row = mysql_fetch_assoc($result); if($result){ ?>

  • <!-- Calling data from the user-> <img src="<? php echo $Row['photo table'];?>"/>

  • <!--Connecting to table -> <? php $sql="select * from posts"; $res= mysql_query ($sql); while ($dados=mysql_fetch_array($res)) { ?>

  • Edit your question, and enter the code you already have, so we can help you.

  • <!--Calling table data -> <? php echo $data['public'] . " <br>";? > <img src="<? php echo $data['fotopost'];?>" />

  • I’m new to André Baill 3, you can help me?

  • It would be nice to take a look at the tour of the site: http://answall.com/tour. for some extra information. The syntax would be the one I showed you, but I needed more information about the tables in order to know the exact answer.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.