1
select @min_price:=min(prd_sale_price),@max_price:=max(prd_sale_price) from ct_product;
select * from ct_product where prd_sale_price=@min_price or prd_sale_price=@max_price;

This query works in mysql console

but

$query = "
select @min_price:=min(prd_sale_price),@max_price:=max(prd_sale_price) from ct_product;
select * from ct_product where prd_sale_price=@min_price or prd_sale_price=@max_price;
";

$result = mysql_query($query);

this code raise error in php

so, I tried this

$query="
select * from ct_product, (select @min_price:=min(prd_sale_price),@max_price:=max   (prd_sale_price) from ct_product) as b 
where prd_sale_price=@min_price or prd_sale_price=@max_price
";

$result = mysql_query($query);

that works

...

$query = "
select @min_price:=min(prd_sale_price),@max_price:=max(prd_sale_price) from ct_product;
select * from ct_product where prd_sale_price=@min_price or prd_sale_price=@max_price;
";

$result = mysql_query($query);

What's the way that this code would work well without modification as my second way?

2
  • 3
    mysql_query, accepts ONE querry only, not 2 Commented Dec 10, 2013 at 2:31
  • Any reason you can't use some flavor of join in your query? As Dagon says, mysql_query will only take one query for one result. Commented Dec 10, 2013 at 2:34

2 Answers 2

4

Use two calls to mysql_query:

$query1 = "select @min_price:=min(prd_sale_price),@max_price:=max(prd_sale_price) from ct_product";
$query2 = "select * from ct_product where prd_sale_price=@min_price or prd_sale_price=@max_price";

mysql_query($query1);
mysql_query($query2);

Variables are associated with a database connection, so they'll persist between the calls.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer.. i try and your code work very well
0

in PHP mysql_query() can handle only one query at a time

You can't make this method handle 2 query at the same time

what I can suggest is using mysql_query() for every query

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.