0

I have the following php code:

mysql_query("SELECT a FROM b WHERE b.c = '".$_REQUEST['companyName']."'");

I also have a string:

$mynumbers = "AND b.question_code IN (1);";

How can I combine this string withing the mysql_query()?

Thanks,

1
  • 1
    /me casts hundreds of comments about stopping using mysql_query Commented Dec 14, 2012 at 6:19

4 Answers 4

1
mysql_query("SELECT a FROM b WHERE b.c = '".$_REQUEST['companyName']."' " . $mynumbers);

But keep in mind that AND GROUP BY all_surveys.question_code IN (1); is incorrect sql and makes no sense.

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

3 Comments

just changed it. Trying it out now. Can you remove your edit?
@Sohel Mansuri: can I remove what? And what exactly have you changed?
No more GROUP BY in question. In order for people to understand, you should erase your edit. :)
0

You can also do like this if you want more simplicity;

$sql="SELECT a FROM b WHERE b.c = '".$_REQUEST['companyName']."'";
$sql.=$mynumbers;

echo $sql;

Also as zerkms said your sql seems to be incorrect

Comments

0

First is, you can not combine above two statements, the alternatively you can do like this- //Here i assume that you want to concatenate 2nd condition on particular situation so you need to add if condition or else you can directly contcate it with "." (dot) operator.

$query = "SELECT a FROM b WHERE b.c = '".$_REQUEST['companyName']."'";

if(//your condition) $query .= "AND GROUP BY b.question_code IN (1);";

mysql_query($query);

Comments

0

Dont use AND before Group By

Try the following code,

$query  = "SELECT a FROM b WHERE b.c = '".$_REQUEST['companyName']."'";
$query .= " GROUP BY b.question_code IN (1)"
mysql_query($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.