I want output from two table..
One table for Product_detail and second table for Product_image
In product_image table all images store separately for particular product_id
I want output from both table :
For particular product_id all detail from Product_detail table and all images from Product_image table
My Code :
<?php
error_reporting(0);
$response = array();
$response1 = array();
require_once __DIR__ . '/db_Connect.php';
// check for post data
if (isset($_GET["pro_id"])) {
$pid = $_GET['pro_id'];
// get a product from products table
//$result = mysql_query("SELECT * FROM product_list WHERE pro_id = '".$pro_id."'");
$q="SELECT product_list.pro_id,product_list.product_name,product_list.product_desc,product_images.image
FROM product_images
INNER JOIN product_list ON product_list.pro_id = product_images.pro_id
WHERE product_list.pro_id = '$pid'";
$res=mysql_query($q);
if (!empty($res)) {
// user node
$response["product"] = array();
$result = mysql_fetch_assoc($res);
//var_dump($result);
$count=count($result['image']);
$count++;
var_dump($count);
$product=array();
$product['pro_id']=$result['pro_id'];
//$product['cat_id']=$result['cat_id'];
$product['product_name']=$result['product_name'];
$product['product_desc']=$result['product_desc'];
//$product['image']="http://friendzfashionz.com/pandora/admin/".$result['image'];
$clr=array();
for($i=0;$i<$count;$i++)
{
$clr[$i]="http://friendzfashionz.com/pandora/admin/".$result['image'];
//var_dump($clr[$i]);
array_push($response1["images"], $clr[$i]);
}
$product['image']=$clr;
array_push($response["product"], $product);
$response["success"] = 1;
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No user found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
Output of this code is :
int(2) {"product":[{"pro_id":"13","product_name":"jeans","product_desc":"Monkey wash ","image":["http:\/\/friendzfashionz.com\/pandora\/admin\/Sub_uploads\/download (1).jpg","http:\/\/friendzfashionz.com\/pandora\/admin\/Sub_uploads\/download (1).jpg"]}],"success":1}
I have two different image of pro_id in product_image table
I want product_details one time and all product_image of that pro_id..
But the problem is it give me first image two times..
Please help to solve this problem...
Product_detail table:
product_image table: