raj_2006
09-26-2006, 11:51 AM
Hi all,
I am facing a sql problem....Lets demonstrate it.
I have a product table where 4 records are there.
pid(product id) is the primary key,autoincremental and cid is the category id.
cid pid
20 1
20 2
20 3
20 4
In another table named special there are 3 records.But in this table there is no primary key.here is also the same pid as in product table.
pid discount
1 10
2 20
3 30
Now i want to show the all products either with discount or without discount
so it will be like this
pid discount
1 10
2 20
3 30
4 no discount //this text i can display.
Now I am writing this query
$pr="select * from product where cid='$master_id'";//Here say the master id is 20
$qpr=mysql_query($pr) or die(mysql_error());
while($prw=mysql_fetch_array($qpr))
{
$pid=$prw['pid'];
$msql="select * from special where pid='$pid'";
$mql=mysql_query($msql) or die(mysql_error());
while($mrw=mysql_fetch_array($mql))
{
?>
//product list display
<?}}?>
But doing this only 3 products are displaying.I think i need to give another condition in the 2nd sql......is it?
Please give me your suggestion
Thanks for your co-operation in advance.
Raj
I am facing a sql problem....Lets demonstrate it.
I have a product table where 4 records are there.
pid(product id) is the primary key,autoincremental and cid is the category id.
cid pid
20 1
20 2
20 3
20 4
In another table named special there are 3 records.But in this table there is no primary key.here is also the same pid as in product table.
pid discount
1 10
2 20
3 30
Now i want to show the all products either with discount or without discount
so it will be like this
pid discount
1 10
2 20
3 30
4 no discount //this text i can display.
Now I am writing this query
$pr="select * from product where cid='$master_id'";//Here say the master id is 20
$qpr=mysql_query($pr) or die(mysql_error());
while($prw=mysql_fetch_array($qpr))
{
$pid=$prw['pid'];
$msql="select * from special where pid='$pid'";
$mql=mysql_query($msql) or die(mysql_error());
while($mrw=mysql_fetch_array($mql))
{
?>
//product list display
<?}}?>
But doing this only 3 products are displaying.I think i need to give another condition in the 2nd sql......is it?
Please give me your suggestion
Thanks for your co-operation in advance.
Raj