how to get multiple data from two different table from one database in php

Pavan Chanda

I am creating shopping website now i have one table call products in which all the products data is stored and i have different table cart in which all the product which are added to cart are stored so basically in cart I have stored productid, userid so now on page called checkout I want to retrieve data in which the data from cart table we will take productid of particular logged in user and from the table products we will show all the product added to cart so basically from cart table we will take the product added to cart and from table products we will show them . now the problem is that i have retrieved the data but it only showing one item and not multiple. Thanks in advance

Here is my code:

<?php	$userid = $_SESSION['userSession'];	
	
require_once 'dbconfig.php';

	$stmt = $DB_con->prepare('SELECT  cartid,userid,productid FROM cart WHERE userid =:uid');
$stmt->execute(array(':uid'=>$userid));
	if($stmt->rowCount() > 0)
	{
		while($rows=$stmt->fetch(PDO::FETCH_ASSOC))
		{
			extract($rows);
			
			{

}
		
?>

	<?php
	$productid = $rows['productid'];
	
					require_once 'dbconfig.php';

	$stmt = $DB_con->prepare('SELECT productid,productname,productcategory,producttype,productprice,productimage1 FROM products WHERE productid = :uid');
$stmt->execute(array(':uid'=>$productid));
	if($stmt->rowCount() > 0)
	{
		while($row=$stmt->fetch(PDO::FETCH_ASSOC))
		{
			extract($row);
			
			{

}
?>		

	
	<div class="bs-example4" data-example-id="simple-responsive-table">
    <div class="table-responsive">
    	    <table class="table-heading simpleCart_shelfItem">
		  <tr>
			<th class="table-grid">Item</th>
					
			<th>Prices<h3></h3></th>
			<th >Delivery </th>
			<th>Subtotal</th>
		  </tr>
			
		  <tr class="cart-header1">
		  <td class="ring-in"><a href="single.html" class="at-in"><img src="thumb/<?php echo $row['productimage1']; ?>" class="img-responsive" alt=""></a>
			<div class="sed">
				<h5><a href="single.html"><?php echo $row['productname']; ?></a></h5>
			
			</div>
			<div class="clearfix"> </div>
			<div class="close2"> </div></td>
			<td>&#x20b9; <?php echo $row['productprice']; ?></td>
			<td>FREE SHIPPING</td>
			<td class="item_price">$100.00</td>
			<td class="add-check"><a class="item_add hvr-skew-backward" href="#">Add To Cart</a></td>
		  </tr>
		 
		 
		  
	</table>
	</div>
	</div>
	<div class="produced">
	<a href="single.html" class="hvr-skew-backward">Produced To Buy</a>
	 </div>
</div>
</div>


<?php
	}
		}
			
	else
	{
		?>
        <div class="col-xs-12">
        	<div class="alert alert-warning">
            	<span class="glyphicon glyphicon-info-sign"></span> &nbsp; No Data Found ...
            </div>
        </div>
        <?php
	}
	
?>		<?php
	}
		}
			
	else
	{
		?>
        <div class="col-xs-12">
        	<div class="alert alert-warning">
            	<span class="glyphicon glyphicon-info-sign"></span> &nbsp; No Data Found ...
            </div>
        </div>
        <?php
	}
	
?>		

b4rt3kk

You should use another and only one query with JOIN statement.

SELECT * FROM cart c JOIN products p ON p.productid = c.productid WHERE c.userid = :uid

The data you will receive will contains products data from cart.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to extract data from multiple databases and replicate to one database having different table structure using Oracle Goldengate?

how to display data in one page from different database table

How to get result from two different table with one single input

How to Data put from database into table in different manner using php

how two get data from 2 different table c#

Get Common data from two different table

How to get multiple data from different relational table in mysql

How to get data in gridview from one table but multiple select statements

How to get data from database and display to table row span in php

PHP SQL : How to save data to multiple database from one html form OR how to copy data from one database to another database automatically

Save multiple data from different database to one database

How to filter database table by a multiple join records from another one table but different types?

Why do one get two different outputs when querying data from firestore database with an async function?

How to transfer data from one table of a database to a table in another database

Spring Batch - How to read from One Table and Write Data into two different table

Inserting data from one table to another in a database(different servers)

How to get data from multiple tables from single sqlite database in one query for iOS application?

How to insert data from 3 different input fields together in one column of table in mysql database in codeigniter

Using a SELECT query to get data from two different tables in database

Selecting data from two different tables of the same database in PHP/ MYSQL

How to update a table in different database with data from current table?

PostgreSQL: How to copy data from one database table to another database

Database: how to get multiple values from two tables having one common column

How to get one set of data from a SQL query from multiple table?

How to merge facts from two different database into Fact table in Datawarehouse?

How to get in order data from two different children in Firebase Realtime Database?

How to get data by mutiple values on one column with different values on other columns from database in Entity Framework?

How to get data from a different database and save it to another database

Get data from two data source and run in one loop in php