0
SELECT g.date,g.description,g.amount AS cash,0 AS cheque FROM generalledger AS g WHERE g.type="cash" AND (g.date=@gdate OR @gdate IS NULL)
UNION ALL
SELECT gg.date,gg.description,0 AS cash, gg.amount AS cheque FROM generalledger AS gg WHERE gg.type="cheque" AND (gg.date=@gdate OR @gdate IS NULL)

I've this query I want to set the @gdate parameter value from php function, I'm using codeigniter. Is there any other way to do this?

0

2 Answers 2

3

Bindings enable you to simplify your query syntax by letting the system put the queries together for you. Consider the following example:

$sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";

$this->db->query($sql, array(3, 'live', 'Rick'));

The question marks in the query are automatically replaced with the values in the array in the second parameter of the query function.

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

1 Comment

I'm not looking for this, I've some sql variable like this SET @gdate := NULL;
0

you should try this

SELECT g.date,g.description,g.amount AS cash,0 AS cheque 
FROM generalledger AS g, (SELECT @gdate := NULL) as a
WHERE g.type="cash" AND (g.date=@gdate OR @gdate IS NULL)
UNION ALL
SELECT gg.date,gg.description,0 AS cash, gg.amount AS cheque 
FROM generalledger AS gg, (SELECT @gdate := NULL) as b
WHERE gg.type="cheque" AND (gg.date=@gadte OR @gdate IS NULL)

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.