Hi,

I am trying to get some info form my database.
I want to see if there is an entry with a certain product_id that also has another column marked as 1.
I want to display the number of rows that contain that combination.

I have tried a few different ways, none of which work. However they are below.

$checkDuplicate = "SELECT * FROM '".$user."' WHERE product_id = '".$id."'";
foreach ($conn->query($checkDuplicate) as $row) {
		$inCart = $row['in_cart'];
} 

$isCartSql = "SELECT COUNT(*) FROM '".$user."' WHERE product_id = '".$id."' AND in_cart = '1'";
$isCart = $conn->prepare($isCartSql);
$isCart->execute();
$inCart = $isCart->rowCount();

with the foreach one, I am getting this error:
Warning: Invalid argument supplied for foreach() in ... on line 3

and the other one, just doesn't give me anything. Nothing is outputted, or if it is, I have no idea where or how to catch it.

Thankyou for your help.

QWaz

Code for fetching the more than one columns from table....

$checkDuplicate = "SELECT * FROM '".$user."' WHERE product_id = '".$id."'";
$Result = mysql_query($Query);

while($row = mysql_fetch_array($Result))
{
$inCart = $row[0];
}

$isCartSql = "SELECT COUNT(*) FROM '".$user."' WHERE product_id = '".$id."' AND in_cart = '1'";
$isCart = $conn->prepare($isCartSql);
$isCart->execute();
$inCart = $isCart->rowCount();

$checkDuplicate = "SELECT * FROM '".$user."' WHERE product_id = '".$id."'";
$Result = mysql_query($Query);

while($row = mysql_fetch_array($Result))
{
$inCart = $row[0];
}

$isCartSql = "SELECT COUNT(*) FROM '".$user."' WHERE product_id = '".$id."' AND in_cart = '1'";
$isCart = $conn->prepare($isCartSql);
$isCart->execute();
$inCart = $isCart->rowCount();

Code For Database Connection...

<?php
// Login & Session example by sde
// connect.php
// replace with your db info
$hostname="localhost";
$mysql_login="root";
$mysql_password="abcd";
$database="test";
if (!($db = mysql_connect($hostname, $mysql_login , $mysql_password))){
  die("Can't connect to mysql.");       
}else{
  if (!(mysql_select_db("$database",$db)))  {
    die("Can't connect to db.");
  }
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.