1

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

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Ankit_Parmar
0

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();

0

$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();

0

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.");
  }
}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.