Page 1 of 1

Convert Query

Posted: Sat Aug 06, 2016 12:15 am
by tqmd1
Sir, I have 2 tables (Arrival + Pouring)
While using following query, I get result shown in images

[img][IMG]http://i65.tinypic.com/2z3xk3q.png[/img][/img]

Code: Select all

select c1.date,sum(nvl(cx.purchase-cx.sold,0))  as opening,c1.purchase,c1.sold,;
		sum(nvl(cx.purchase-cx.sold,0)) + c1.purchase-c1.sold as closing ;
	from ;
		(select NVL(a.date,b.date) as date,CAST(NVL(a.qty,0) as integer) as purchase,;
		CAST(NVL(b.qty,0) as integer) as sold from purchase a FULL JOIN sold b ON a.date = b.date order by 1) c1 ;
	left join;
	 (select NVL(a.date,b.date) as date,CAST(NVL(a.qty,0) as integer) as purchase,;
	 CAST(NVL(b.qty,0) as integer) as sold from purchase a FULL JOIN sold b ON a.date = b.date order by 1) cx ;
	on c1.date>cx.date;
	 group by c1.date,c1.purchase,c1.sold
	 
The query work fine, but I want to use PHP codes to get result.
Is it possible?

Re: Convert Query

Posted: Sat Aug 06, 2016 2:39 pm
by Christopher
tqmd1 wrote:The query work fine, but I want to use PHP codes to get result.
Is it possible?
Yes. If you have PHP setup with with the extension for your database. I'd recommend you use PDO. See the manual for configuring it for your database: http://php.net/manual/en/pdo.drivers.php.

There are code examples in the manual for everything.

You first need to connect to the database with PHP:
http://php.net/manual/en/pdo.construct.php

Then execute the query:
http://php.net/manual/en/pdo.exec.php

And fetch a record:
http://php.net/manual/en/pdostatement.fetch.php

Or you can fetch all records:
http://php.net/manual/en/pdostatement.fetchall.php

If you have problems, just post your code here and we'll help.