php - If IDs from two different tables are equal, display name from another table -


i'm writing code little admin panel, , since i'm not advanced of coder, i'm experiencing troubles getting name using 2 different tables.

here's code far:

<?php  session_start(); if(!session_is_registered(myusername)){     header("location:main_login.php"); }  include 'db_connect.php';  $sql = "select * $tbl_name is_dead='0'"; $result=mysql_query($sql); ?>  <title>title</title> <center><img src="header.png"></center> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td> <table width="400" border="1" cellspacing="0" cellpadding="3"> <tr> <? include 'menu.php';?> </tr>  <tr> <td align="center"><strong>id</strong></td> <td align="center"><strong>unique id</strong></td> <td align="center"><strong>model</strong></td> <td align="center"><strong>last online</strong></td> <td align="center"><strong>options</strong></td> </tr>  <?php while($rows=mysql_fetch_array($result)){ ?>  <tr> <td><? echo $rows['id']; ?></td> <td><? if ($rows['unique_id'] == 7815684) { echo '<font color="blue"><b><u>7815684</u></b></font>'; } elseif ($rows['unique_id'] == 2312964) { echo '<font color="blue"><b><u>2312964</u></b></font>'; } else { echo $rows['unique_id']; } ?></td> <td><? echo $rows['model']; ?></td> <td align='center'><font color="green"><b><? echo $rows['last_updated']; ?></b></font></td> <td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a> </tr> <?php } ?>  </table> </td> </tr> </table> 

so i'm trying user name, using 2 tables $tbl_name , $prtalbe using unique_id. so, if unique_id $tbl_name equals unique_id $prtable, want show user's name $prtalbe.

i've been trying sql query:

$sql = "select * $tbl_name, $prtable $tbl_name.unique_id = $prtable.unique_id; $result=mysql_query($sql); 

then doing while loop working

while($rows=mysql_fetch_array($result)){    $rows['name']; } 

and did work actually, didn't want put right code, since id $prtable , $tbl_name different.

try this:

$sql = "select $prtable.username $tbl_name inner join $prtable on ($tbl_name.unique_id = $prtable.unique_id)";  

when call inner join fetching rows each table , combining them given on condition. more information, see this: http://www.w3schools.com/sql/sql_join_inner.asp


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -