1

I'm facing a problem to display a name on a table, only the id is displayed I have tried some inner join queries without luck i got 2 tables

Table 1 = empresas

Here is where all the data lives:

example1

the number 9 in u_tip corresponds to the ID of the data that is in tipoempresas table

Table 2 = tipoempresas

example2

I want to display the name of the type not the ID

I'm using this code to display the data in a html table

$result = mysqli_query($conn,"SELECT * FROM empresas");


$i = 0;
while($row = $result->fetch_assoc())
{
echo "<tr>";
foreach ($row as $value) {
  echo "<td>" . $value . "</td>";
}
echo "</tr>";
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • you can learn more about inner join here: https://stackoverflow.com/questions/1018822/inner-join-on-vs-where-clause – Sofyan Thayf Mar 01 '18 at 00:49
  • 1 Please [use text, not images/links, for text (including code, tables & ERDs)](https://meta.stackoverflow.com/q/285551/3404097). Use an image only for convenience to supplement text and/or for what cannot be given in text. Use edit functions to inline, not link, if you have the rep--make your post self-contained. 2 Always google many clear, concise & specific versions/phrasings of your question/problem/goal & read many answers. Add relevant keywords you discover to your searches. If you don't find an answer then post, using use one variant search for your title & keywords for your tags. – philipxy Mar 01 '18 at 01:22
  • Possible duplicate of [PHP MySQL get data from 2 tables](https://stackoverflow.com/questions/12297324/php-mysql-get-data-from-2-tables). All you had to do was google 'sql get data from two tables php'. – philipxy Mar 01 '18 at 01:30

1 Answers1

0

You are already there you just need to use join statement and specify the column you want to display

$result = mysqli_query($conn,"SELECT * FROM empresas AS e INNER JOIN tipoempresas AS t ON t.id = e.u_tip");


$i = 0;
while($row = $result->fetch_assoc())
{
echo "<tr>";
foreach ($row as $value) {
 echo "<td>" . $value['Nombre'] . "</td>"; //SPECIFY THE COLUMN YOU WANT TO DISPLAY
}
echo "</tr>";
jerome
  • 695
  • 6
  • 20