Right Join php mysql
run the following scripts and note the difference between left join and right join.
<?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 RIGHT 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> |
Codes above are created bellow table.Now you can see right join results are opposite to the results in left join.
Product Name | Customer Name |
Photoshop Cs5 | Harfer |
Ilustrator cs5 | Taylor |
Win 2007 | Jones |
Maya 10 | Lopez |
3D Max 9 | Bayker |
wonne | |
hare |
No comments:
Post a Comment