Jump to content

[SOLVED] join 2 tables how?


Thundarfoot

Recommended Posts

I am a noob working on my second script.

I have 2 tables A & B

Table A has 3 columns, the third column contains a number which represents the id of an entry in table B.

 

I know how to query table a for its 3 columns and can show that output in a dynamic table.

However this just shows the number in the thrid column....

 

I need to figure out how to take the number and fetch the correct entry from table b instead.

Any help would be appreciated.

Thank you for your time.

Link to comment
https://forums.phpfreaks.com/topic/88702-solved-join-2-tables-how/
Share on other sites

thank you for that link, it helps explain things a lot. But I am still having trouble making it work.

I belive the join code I need to use is..

 

SELECT *

FROM  cubes

      LEFT OUTER JOIN mobs

          ON drops_from.id = mobs.id

 

Should I be placing this in a query? I have tried to add the abovet o a query command but to no avail.

here is the code I am working with now...

 

Thank you in advance for any help you can give.

 

mysql_select_db($database_LWC, $LWC);
$query_Rs1_cubes = "SELECT * FROM cubes";
$Rs1_cubes = mysql_query($query_Rs1_cubes, $LWC) or die(mysql_error());
$row_Rs1_cubes = mysql_fetch_assoc($Rs1_cubes);
$totalRows_Rs1_cubes = mysql_num_rows($Rs1_cubes);

mysql_select_db($database_LWC, $LWC);
$query_Rs2_Mobs = "SELECT * FROM mobs";
$Rs2_Mobs = mysql_query($query_Rs2_Mobs, $LWC) or die(mysql_error());
$row_Rs2_Mobs = mysql_fetch_assoc($Rs2_Mobs);
$totalRows_Rs2_Mobs = mysql_num_rows($Rs2_Mobs);

?>

<html>
<body>
<table border="1">
  <tr>
    <td>id</td>
    <td>Cube Type</td>
    <td>Drops From</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_Rs1_cubes['id']; ?></td>
      <td><?php echo $row_Rs1_cubes['Cube Type']; ?></td>
      <td><?php echo $row_Rs1_cubes['Drops From']; ?></td>
    </tr>
    <?php } while ($row_Rs1_cubes = mysql_fetch_assoc($Rs1_cubes)); ?>
</table>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Rs1_cubes);

mysql_free_result($Rs2_Mobs);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.