Convert Query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tqmd1
Forum Newbie
Posts: 7
Joined: Sat Nov 09, 2013 1:07 am

Convert Query

Post 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?
Attachments
result.png
result.png (7.76 KiB) Viewed 3309 times
table_pouring.png
table_arrival.png
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Convert Query

Post 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.
(#10850)
Post Reply