I cant find good solution to get information from other mysql tables when I have Main table (PC) which are connected to other tables (cpu, ram, hdd..). In PC table there is other components IDs (cpu, ram, hdd..).
There is the code which I am using:
<?php
$query="SELECT * FROM pc ORDER by id";
mysql_query("SET NAMES 'UTF8'");
$result = mysql_query ($query);
$i=1;
echo '<table border = "1">';
echo '<tr><td><b>Nr.</b></td><td><b>CPU:</b></td><td><b>RAM</b></td><td><b>HDD</b></td><td><b>MB</b></td><td><b>GPU</b></td><td><b>Monitor</b></td></tr>';
while($nt=mysql_fetch_array($result)){
$proc = $nt['proc_id'];
$ram = $nt['ram_id'];
$hdd = $nt['hdd_id'];
$mb = $nt['mot_id'];
$gpu = $nt['gpu_id'];
$mon = $nt['monit_id'];
echo '<tr><td><b>'.$i++.'.</b></td><td>'.$proc.'</td><td>'.$ram.'</td><td>'.$hdd.'</td><td>'.$mb.'</td><td>'.$gpu.'</td><td>'.$mon.'</td></tr>';
}
echo '</table>';
?>
_______________________________
|Nr. CPU RAM GPU HDD MONITOR |
| 1 1 2 1 2 2 |
---------------------------------
I’m getting the list of parts ID numbers, but instead of this I need to print real names of these components which is in other tables,not IDs. So my question is how to use IDs which are in PC table to get item name containing that ID. For example:
________________________________________________________
|Nr. CPU RAM GPU HDD MONITOR |
| 1 Intel 2gb adata GTX 460 WD 1tb LCD.. |
---------------------------------------------------------
Hope you understood my question, thanks.
change:
to something like
For an improved understanding of Joins see http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html