Friday, June 8, 2012

Inner Join php

Inner Join php
Result of inner join is similar to simple join.Display of additional records in right join and left join are corrected with inner join.Create following script & run it.

<?php
$host="localhost";
$username="root";
$password="";
$db_name="my_database";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql ="SELECT product.product_name, customer.customer_name FROM product
    INNER JOIN  customer ON customer.product_id=product.product_id ";
     $result=mysql_query($sql);
?>
<table  align="center"  bgcolor="#15475c">
<tr bgcolor="#ddeef5">
<td align="center" ><strong>Product Name</strong></td>
<td align="center" "><strong>Customer Name</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr bgcolor="#d0e7f1">
<td><?php echo $rows['product_name']; ?></td>
<td><?php echo $rows['customer_name']; ?></td>
</tr>
<?php
}
?>
</table>

Resulting table is

Product Name Customer Name
Photoshop Cs5 Harfer
Ilustrator cs5 Taylor
Win 2007 Jones
Maya 10 Lopez
3D Max 9 Bayker
Next

No comments:

Post a Comment