Click here to Skip to main content
15,614,766 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:

$query="select Pname,price,time,days from package";

 mysqli_stmt_prepare($stmt,$query) or exit('Query Error.'. mysqli_stmt_errno($stmt));
 mysqli_stmt_execute($stmt) or exit('Query Execution failed.'. mysqli_stmt_errno($stmt));
 mysqli_stmt_bind_result($stmt,$Pname,$price,$time,$days) or exit('Result storage failed.'. mysqli_stmt_errno($stmt));

echo '<table border="1"><tr><th>Pname</th><th>price</th><th>time</th><th>days</th><th>users</th></tr>';

		echo '<tr>';
		echo "<td>$Pname</td>";
		echo "<td>$price</td>";
		echo "<td>$time</td>";
		echo "<td>$days</td>";
		echo '<td></td>';
		echo '</tr>';
echo '</table><br/>';
echo mysqli_stmt_num_rows($stmt).' records found<br/>'; 



What I have tried:

i have two database tables
one for users
and one for packages information
in the user table i have package_id as well to connect the package name with the user who choose the package

i already can display the packages information in the table but i couldn't display the users beside them
Updated 10-Jan-22 3:31am

1 solution

I think you need to inner join
How to Use Joins in PHP[^]

here is an example
$qry="SELECT,emp.FirstName, dept.dept_name FROM emp INNER JOIN dept on = dept.dept_id";

this connects to separate tables

in your case I guess it would be something like this ( I added a fake user row because I don't know what your users table looks like)
$query="select package.Pname,package.price,package.time,package.days, from package INNER JOIN users on package.package_id = users.package_id";
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900