Site icon T4Tutorials.com

inner join program code in PHP, MySQL

right join php mysql

right join php mysql

Inner join shows results from both tables where there is any match between columns in both tables.
In this example, the table t4tutorials_finance is joining as the inner join with user_details table.
joins PHP MySQLi

The query of  Inner Join

select * from t4tutorials_finance inner join user_details on user_details.userid=T4Tutorials_finance.t4tutorials_id

Inner Join Program Example in PHP, MYSQL

<!DOCTYPE html>
<html>
<head>
	<title>Left Join Tables using Left Join PHP and MySQLi</title>
</head>
<body>
	<table border="1">
		<thead>
			<th>Salary</th>
			<th>Firstname</th>
			<th>Lastname</th>
		</thead>
		<tbody>
		<?php
	$conn = mysqli_connect("localhost","root","","t4tutorials_Join");
	// Check connection
	if (mysqli_connect_errno())
 	 {
	  echo "Failed to connect to MySQL: " . mysqli_connect_error();
	  }
		$query=mysqli_query($conn,"select * from `t4tutorials_finance` inner join user_details on 	user_details.userid=T4Tutorials_finance.t4tutorials_id");
			while($row=mysqli_fetch_array($query)){
				?>
					<tr>
					<td><?php echo $row['t4tutorials_salary']; ?></td>
					<td><?php echo $row['firstname']; ?></td>
					<td><?php echo $row['lastname']; ?></td>
					</tr>
				<?php
			}
		?>
			
		</tbody>
	</table>
</body>
</html>

The database for the inner join program is shown below.

Video Lecture

Database t4tutorials_join for inner join

Download the database

Table structure for table t4tutorials_finance

Column Type Null Default
t4tutorials_id int(222) No
t4tutorials_salary int(222) No

Table structure for table user_details

Column Type Null Default
userid int(11) No
firstname varchar(30) No
lastname varchar(30) No
Exit mobile version