Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Query{
- public $select;
- public $from;
- public $where;
- public $select_input = 'SELECT ';
- public $join_input = '';
- public $where_input = ' WHERE ';
- public $modified_cols = array('Location' => array('WarehouseLocation.Name AS Location', 'INNER JOIN WarehouseLocation ON Stockitem.Location = WarehouseLocation.Code'),
- 'Product' => array('Product.Name AS Product', 'INNER JOIN Product ON Stockitem.Product = Product.Code'),
- 'Manufacturer' => array('Manufacturer.Name AS Manufacturer', 'LEFT JOIN Manufacturer ON (Manufacturer = Manufacturer.Code)'),
- 'Model' => array('ProductModel.Name AS Model', 'LEFT JOIN ProductModel ON (ProductModel.Code = StockItem.Model)'),
- 'Customer' => array('Customer.Name as Customer', 'LEFT JOIN Customer ON (Customer.Code = StockItem.Customer)'),
- 'Status' => array('Status.Name AS Status', 'INNER JOIN Status ON Stockitem.Status = Status.Code'),
- 'Owner' => array('Owner.Name AS Owner', 'INNER JOIN Owner ON Stockitem.Owner = Owner.Code'),
- 'Condition' => array('Condition.Name AS Condition', 'INNER JOIN Condition ON Stockitem.Condition = Condition.Code')
- );
- public function __construct($select, $from, $where){
- $this->select = $select;
- $this->from = $from;
- $this->where = $where;
- }
- public function try_this(){
- foreach($this->select as $s){
- if(isset($this->modified_cols[$s])){
- $this->select_input .= $this->modified_cols[$s][0] . ',';
- $this->join_input .= $this->modified_cols[$s][1] . ',';
- }else{
- $this->select_input .= $s . ','; }
- }
- $this->select_input = substr($this->select_input, 0, -1);
- $this->join_input = substr($this->join_input, 0, -1);
- }
- // public $count = sqlsrv_num_rows($this->output);
- }
- $q = new Query(array('Product', 'Model', 'ItemCode'), 'StockItem', 'Owner.Code=69');
- // $q->query();
- // print_r($q->select);
- $q->try_this();
- echo $q->join_input;
- /** $query_item_input = 'SELECT ItemCode, WarehouseLocation.Name AS Location, AuditDate, Product.Name AS Product,
- Manufacturer.Name AS Manufacturer, ProductModel.Name AS Model, Customer.Name as Customer,
- Status.Name AS Status, PCSerialNo, DisplayCode, BuyPrice, AuditCharge, FreightCharge,
- MiscCharge, AvailableForSale, Owner.Name AS Owner, Condition.Name AS Condition
- FROM StockItem
- INNER JOIN Product ON Stockitem.Product = Product.Code
- INNER JOIN Owner ON Stockitem.Owner = Owner.Code
- INNER JOIN Status ON Stockitem.Status = Status.Code
- INNER JOIN WarehouseLocation ON Stockitem.Location = WarehouseLocation.Code
- INNER JOIN Condition ON Stockitem.Condition = Condition.Code
- LEFT JOIN Manufacturer ON (Manufacturer = Manufacturer.Code)
- LEFT JOIN ProductModel ON (ProductModel.Code = StockItem.Model)
- LEFT JOIN Customer ON (Customer.Code = StockItem.Customer)
- WHERE Owner.Code = ' . intval($_SESSION['company_id']) . $date_str . $sale_str . ';';
- // Executes the query
- $query_item_output = sqlsrv_query($conn, $query_item_input, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
- $row_count = sqlsrv_num_rows($query_item_output);
- $all_stock_arr = array();
- if ($query_item_output === false) {
- die(formatErrors(sqlsrv_errors()));
- echo 'Connection status: DOWN';}
- while( $row = sqlsrv_fetch_array( $query_item_output, SQLSRV_FETCH_ASSOC) ) {
- $all_stock_arr[] = $row;}
- sqlsrv_free_stmt($query_item_output);
- sqlsrv_close($conn);**/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement