edgarasm Posted March 6, 2014 Share Posted March 6, 2014 Hello PHP freaks Im trying to display table contents as Uploads or widrawals but would i have to create the functions inside the Widrawals and Uploads in order for it to be displayed in Overview table ? My code for overview table controller so far : By the way I'm using code igniter public function index() { $this->data['site']['currentNav'] = "account"; $query = $this->db->query("SELECT C.card_number AS `card_number` FROM `cards` C WHERE C.accountID = '". $this->account_id ."' AND C.status = '1'"); $this->data['cards'] = $query->result(); $query = $this->db->query("SELECT B.account_number AS `account_number`, B.sortcode AS `sortcode` FROM `banks` B WHERE B.accountID = '". $this->account_id ."' AND B.status = '1'"); $this->data['banks'] = $query->result(); $query = $this->db->query("SELECT T.transaction AS `transactionID`, T.timestamp AS `date`, IF(T.to = '". $this->account_id ."', 'Received', 'Sent') AS `type`, CONCAT(A.firstname, ' ', A.lastname) AS `name`, T.amount AS `amount` FROM `transactions` T JOIN `accounts` A ON (A.id = T.from) WHERE (T.to = '". $this->account_id ."' || T.from = '". $this->account_id ."') ORDER BY T.id DESC LIMIT 10"); $this->data['transactions'] = $query->result(); $this->load->view('_template/header', $this->data); $this->load->view('account/index', $this->data); $this->load->view('_template/footer', $this->data); } Quote Link to comment https://forums.phpfreaks.com/topic/286765-withdrawals-and-uploads/ Share on other sites More sharing options...
Skewled Posted March 7, 2014 Share Posted March 7, 2014 I've been using CodeIgniter for a project I'm working on and I have become quite fond of it. If you want your Overview View to display the information than you need to keep it in the Overview Controller for consistency. Does this Controller actually load the view properly? Typically the Controller is a class that links to a model and view but I guess you didn't post the entire Controller? Quote Link to comment https://forums.phpfreaks.com/topic/286765-withdrawals-and-uploads/#findComment-1471720 Share on other sites More sharing options...
edgarasm Posted March 7, 2014 Author Share Posted March 7, 2014 Yes i didn't post the whole controller ,would you like me to do the whole one ? maybe it would of been better in the first place Because at the moment it works for transfers between people ,i need to make it so it displays the uploads and withdrawals work aswell <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Account extends Overview { public function __construct(){ parent::__construct(); !self::isLoggedin() ? redirect("/") : null; } public function index() { $this->data['site']['currentNav'] = "account"; $query = $this->db->query("SELECT C.card_number AS `card_number` FROM `cards` C WHERE C.accountID = '". $this->account_id ."' AND C.status = '1'"); $this->data['cards'] = $query->result(); $query = $this->db->query("SELECT B.account_number AS `account_number`, B.sortcode AS `sortcode` FROM `banks` B WHERE B.accountID = '". $this->account_id ."' AND B.status = '1'"); $this->data['banks'] = $query->result(); $query = $this->db->query("SELECT T.transaction AS `transactionID`, T.timestamp AS `date`, IF(T.to = '". $this->account_id ."', 'Received', 'Sent') AS `type`, CONCAT(A.firstname, ' ', A.lastname) AS `name`, T.amount AS `amount` FROM `transactions` T JOIN `accounts` A ON (A.id = T.from) WHERE (T.to = '". $this->account_id ."' || T.from = '". $this->account_id ."') ORDER BY T.id DESC LIMIT 10"); $this->data['transactions'] = $query->result(); $this->load->view('_template/header', $this->data); $this->load->view('account/index', $this->data); $this->load->view('_template/footer', $this->data); } public function transfer() { $this->data['site']['currentNav'] = "account"; $this->load->view('_template/header', $this->data); $this->load->view('account/transfer', $this->data); $this->load->view('_template/footer', $this->data); } public function transfer_process() { $submit = $this->input->post("submit"); if(empty($submit)) { redirect("/index.php/account/transfer"); } $this->load->library('form_validation'); $this->form_validation->set_rules('email', 'email', 'required'); $this->form_validation->set_rules('amount', 'amount', 'required'); $this->form_validation->set_rules('description', 'description', 'required'); $this->data['post']['email'] = $this->input->post("email"); $this->data['post']['amount'] = $this->input->post("amount"); $this->data['post']['description'] = $this->input->post("description"); if ($this->form_validation->run() == FALSE) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">". validation_errors() ."</a>"; self::transfer(); } else { $query = $this->db->query("SELECT A.`id` FROM `accounts` A WHERE A.email = '". $this->input->post("email") ."'"); $results = $query->row(); $transaction = $this->generateRandomString(32); $amount = $this->input->post("amount"); $accountType = $this->data['account']->accountType; $fees = $this->calculateFees('Transfer', $accountType, $amount); $fees = $fees->fees; $fees = ($amount * ($fees / 100)); $final = ($amount - $fees); if($final > $this->data['account']->amount){ $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">You do not have enough funds to complete this transaction.</a>"; self::transfer(); } elseif($query->num_rows() == 0) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">The email address does not exist. Please check before continuing.</a>"; self::transfer(); } else { $data = array( 'transaction' => "TP_" . $transaction, 'amount' => $amount, 'to' => $results->id, 'from' => $this->account_id, 'status' => 1 ); $this->db->insert('transactions', $data); $this->db->query("UPDATE accounts SET amount = (amount - ". $amount .") WHERE id = '". $this->account_id ."'"); $this->db->query("UPDATE accounts SET amount = (amount + ". $final .") WHERE id = '". $results->id ."'"); $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification success\">You have successfully sent " . number_format($amount, 2) . "</b>)</a>"; $this->data['post']['email'] = ""; $this->data['post']['amount'] = ""; $this->data['post']['description'] = ""; self::transfer(); } } } public function transactions() { $this->data['site']['currentNav'] = "account"; $query = $this->db->query("SELECT T.transaction AS `transactionID`, T.timestamp AS `date`, IF(T.to = '". $this->account_id ."', 'Received', 'Sent') AS `type`, CONCAT(A.firstname, ' ', A.lastname) AS `name`, T.amount AS `amount` FROM `transactions` T JOIN `accounts` A ON (A.id = T.from) WHERE (T.to = '". $this->account_id ."' || T.from = '". $this->account_id ."') ORDER BY T.id DESC"); $this->data['transactions'] = $query->result(); $this->load->view('_template/header', $this->data); $this->load->view('account/transactions', $this->data); $this->load->view('_template/footer', $this->data); } public function withdrawal() { $submit = $this->input->post("submit"); $bank = $this->input->post("bank"); $amount = $this->input->post("amount"); $this->data['post']['bank'] = $bank; $this->data['post']['amount'] = $amount; if($submit) { if(empty($bank)) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">Please select a bank account.</a>"; } elseif(empty($amount)) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">Please enter an amount to withdraw.</a>"; } elseif($amount > $this->data['account']->amount) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">You do not have enough funds to complete this withdrawal.</a>"; } else { $accountType = $this->data['account']->accountType; $fees = $this->calculateFees('Withdrawal', $accountType, $amount); $fees = $fees->fees; $fees = ($amount * ($fees / 100)); $final = ($amount + $fees); $this->db->query("INSERT INTO withdrawal_transactions (accountID, amount, bankID, status) VALUES ('". $this->account_id ."', '". $amount ."', '". $bank ."', '1')"); $this->db->query("UPDATE accounts SET amount = (amount - ". $final .") WHERE id = '". $this->account_id ."'"); $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification success\">Your (€". $amount ." + Fees: €". $fees .") withdrawal was successful.</a>"; $this->data['post']['bank'] = ''; $this->data['post']['amount'] = ''; } } $this->data['site']['currentNav'] = "account"; $query = $this->db->query("SELECT B.id AS `id`, B.account_number AS `account_number`, B.sortcode AS `sortcode` FROM `banks` B WHERE B.accountID = '". $this->account_id ."' AND B.status = '1'"); $this->data['banks'] = $query->result(); $this->load->view('_template/header', $this->data); $this->load->view('account/withdrawal', $this->data); $this->load->view('_template/footer', $this->data); } public function upload() { $submit = $this->input->post("submit"); $bank = $this->input->post("bank"); $card = $this->input->post("card"); $amount = $this->input->post("amount"); $this->data['post']['bank'] = $bank; $this->data['post']['card'] = $card; $this->data['post']['amount'] = $amount; if($submit) { if(empty($bank) && empty($card)) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">Please select either a bank account or debit/credit card.</a>"; } elseif(!empty($bank) && !empty($card)) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">Please only choose one upload method at a time.</a>"; } elseif(empty($amount)) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">Please enter an amount to withdraw.</a>"; } else { $accountType = $this->data['account']->accountType; $fees = $this->calculateFees('Withdrawal', $accountType, $amount); $fees = $fees->fees; $fees = ($amount * ($fees / 100)); $final = ($amount - $fees); $this->db->query("INSERT INTO upload_transactions (accountID, amount, bankID, cardID, status) VALUES ('". $this->account_id ."', '". $amount ."', '". $bank ."', '". $card ."', '1')"); $this->db->query("UPDATE accounts SET amount = (amount + ". $final .") WHERE id = '". $this->account_id ."'"); $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification success\">Your (€". $amount ." + Fees: €". $fees .") upload was successful.</a>"; $this->data['post']['bank'] = ''; $this->data['post']['amount'] = ''; $this->data['post']['card'] = ''; } } $this->data['site']['currentNav'] = "account"; $query = $this->db->query("SELECT C.id, C.card_number AS `card_number` FROM `cards` C WHERE C.accountID = '". $this->account_id ."' AND C.status = '1'"); $this->data['cards'] = $query->result(); $query = $this->db->query("SELECT B.id, B.account_number AS `account_number`, B.sortcode AS `sortcode` FROM `banks` B WHERE B.accountID = '". $this->account_id ."' AND B.status = '1'"); $this->data['banks'] = $query->result(); $this->load->view('_template/header', $this->data); $this->load->view('account/upload', $this->data); $this->load->view('_template/footer', $this->data); } public function details() { $submit = $this->input->post("submit"); $this->data['post']['email'] = $this->data['account']->email; $this->data['post']['firstname'] = $this->data['account']->firstname; $this->data['post']['lastname'] = $this->data['account']->lastname; $this->data['post']['address_one'] = $this->data['account']->address_one; $this->data['post']['address_two'] = $this->data['account']->address_two; $this->data['post']['town_city'] = $this->data['account']->town; $this->data['post']['county_option'] = $this->data['account']->county; $this->data['post']['post_code'] = $this->data['account']->postcode; $this->data['post']['phone_number'] = $this->data['account']->phone_number; if($submit){ $this->load->library('form_validation'); $this->form_validation->set_rules('email', 'email', 'required'); $this->form_validation->set_rules('firstname', 'firstname', 'required'); $this->form_validation->set_rules('lastname', 'lastname', 'required'); $this->form_validation->set_rules('address_one', 'address_one', 'required'); $this->form_validation->set_rules('address_two', 'address_two', 'required'); $this->form_validation->set_rules('town_city', 'town', 'required'); $this->form_validation->set_rules('county_option', 'county', 'required'); $this->form_validation->set_rules('post_code', 'postcode', 'required'); $this->form_validation->set_rules('phone_number', 'phone number', 'required'); $this->data['post']['email'] = $this->input->post("email"); $this->data['post']['firstname'] = $this->input->post("firstname"); $this->data['post']['lastname'] = $this->input->post("lastname"); $this->data['post']['address_one'] = $this->input->post("address_one"); $this->data['post']['address_two'] = $this->input->post("address_two"); $this->data['post']['town_city'] = $this->input->post("town_city"); $this->data['post']['county_option'] = $this->input->post("county_option"); $this->data['post']['post_code'] = $this->input->post("post_code"); $this->data['post']['phone_number'] = $this->input->post("phone_number"); $this->data['post']['password'] = $this->input->post("password"); $this->data['post']['confirm'] = $this->input->post("confirm"); if ($this->form_validation->run() == FALSE) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">". validation_errors() ."</a>"; } else { if($this->data['post']['password'] != $this->data['post']['confirm']){ $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">Your newly entered passwords do not match.</a>"; } else { $update = array( 'email' => $this->data['post']['email'], 'firstname' => $this->data['post']['firstname'], 'lastname' => $this->data['post']['lastname'], 'address_one' => $this->data['post']['address_one'], 'address_two' => $this->data['post']['address_two'], 'town' => $this->data['post']['town_city'], 'county' => $this->data['post']['county_option'], 'postcode' => $this->data['post']['post_code'], 'phone_number' => $this->data['post']['phone_number'] ); $this->db->where('id', $this->account_id); $this->db->update('accounts', $update); $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification success\">You have changed your details successfully.</a>"; } } } $this->data['site']['currentNav'] = "account"; $this->load->view('_template/header', $this->data); $this->load->view('account/details', $this->data); $this->load->view('_template/footer', $this->data); } public function addcard() { $submit = $this->input->post("submit"); if($submit){ $this->load->library('form_validation'); $this->form_validation->set_rules('card', 'card', 'required'); $this->form_validation->set_rules('expiry', 'expiry', 'required'); $this->form_validation->set_rules('security', 'security', 'required'); $this->data['post']['card'] = $this->input->post("card"); $this->data['post']['expiry'] = $this->input->post("expiry"); $this->data['post']['security'] = $this->input->post("security"); if ($this->form_validation->run() == FALSE) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">". validation_errors() ."</a>"; } else { $insert = array( 'accountID' => $this->account_id, 'card_number' => $this->data['post']['card'], 'expiry' => $this->data['post']['expiry'], 'security' => $this->data['post']['security'], 'status' => 1 ); $this->db->insert('cards', $insert); $this->data['post']['card'] = ""; $this->data['post']['expiry'] = ""; $this->data['post']['security'] = ""; $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification success\">You have successfully added a new card.</a>"; } } $this->data['site']['currentNav'] = "account"; $this->load->view('_template/header', $this->data); $this->load->view('account/addcard', $this->data); $this->load->view('_template/footer', $this->data); } public function addbank() { $submit = $this->input->post("submit"); if($submit){ $this->load->library('form_validation'); $this->form_validation->set_rules('account_number', 'account_number', 'required'); $this->form_validation->set_rules('sortcode', 'sortcode', 'required'); $this->data['post']['account_number'] = $this->input->post("account_number"); $this->data['post']['sortcode'] = $this->input->post("sortcode"); if ($this->form_validation->run() == FALSE) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">". validation_errors() ."</a>"; } else { $insert = array( 'accountID' => $this->account_id, 'account_number' => $this->data['post']['account_number'], 'sortcode' => $this->data['post']['sortcode'], 'status' => 1 ); $this->db->insert('banks', $insert); $this->data['post']['account_number'] = ""; $this->data['post']['sortcode'] = ""; $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification success\">You have successfully added a new bank account.</a>"; } } $this->data['site']['currentNav'] = "account"; $this->load->view('_template/header', $this->data); $this->load->view('account/addbank', $this->data); $this->load->view('_template/footer', $this->data); } public function paymentmethods() { $this->data['site']['currentNav'] = "account"; $query = $this->db->query("SELECT C.id AS `id`, C.card_number AS `card_number`, C.expiry AS `expiry` FROM `cards` C WHERE C.accountID = '". $this->account_id ."' AND C.status = '1'"); $this->data['cards'] = $query->result(); $query = $this->db->query("SELECT B.id AS `id`, B.account_number AS `account_number`, B.sortcode AS `sortcode` FROM `banks` B WHERE B.accountID = '". $this->account_id ."' AND B.status = '1'"); $this->data['banks'] = $query->result(); $this->load->view('_template/header', $this->data); $this->load->view('account/paymentmethods', $this->data); $this->load->view('_template/footer', $this->data); } public function delcard() { $card_id = $this->uri->segment(3, 0); $update = array( 'status' => 0 ); $this->db->where('id', $card_id); $this->db->update('cards', $update); redirect("/index.php/account/paymentmethods"); } public function delbank() { $card_id = $this->uri->segment(3, 0); $update = array( 'status' => 0 ); $this->db->where('id', $card_id); $this->db->update('banks', $update); redirect("/index.php/account/paymentmethods"); } } Quote Link to comment https://forums.phpfreaks.com/topic/286765-withdrawals-and-uploads/#findComment-1471751 Share on other sites More sharing options...
Skewled Posted March 7, 2014 Share Posted March 7, 2014 Let's take a look at the upload section first. public function upload() { $submit = $this->input->post("submit"); $bank = $this->input->post("bank"); $card = $this->input->post("card"); $amount = $this->input->post("amount"); $this->data['post']['bank'] = $bank; $this->data['post']['card'] = $card; $this->data['post']['amount'] = $amount; if($submit) { if(empty($bank) && empty($card)) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">Please select either a bank account or debit/credit card.</a>"; } elseif(!empty($bank) && !empty($card)) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">Please only choose one upload method at a time.</a>"; } elseif(empty($amount)) { $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification error\">Please enter an amount to withdraw.</a>"; } else { $accountType = $this->data['account']->accountType; $fees = $this->calculateFees('Withdrawal', $accountType, $amount); $fees = $fees->fees; $fees = ($amount * ($fees / 100)); $final = ($amount - $fees); $this->db->query("INSERT INTO upload_transactions (accountID, amount, bankID, cardID, status) VALUES ('". $this->account_id ."', '". $amount ."', '". $bank ."', '". $card ."', '1')"); $this->db->query("UPDATE accounts SET amount = (amount + ". $final .") WHERE id = '". $this->account_id ."'"); $this->data['post']['error_message'] = "<a href=\"#\" class=\"notification success\">Your (€". $amount ." + Fees: €". $fees .") upload was successful.</a>"; $this->data['post']['bank'] = ''; $this->data['post']['amount'] = ''; $this->data['post']['card'] = ''; } } $this->data['site']['currentNav'] = "account"; $query = $this->db->query("SELECT C.id, C.card_number AS `card_number` FROM `cards` C WHERE C.accountID = '". $this->account_id ."' AND C.status = '1'"); $this->data['cards'] = $query->result(); $query = $this->db->query("SELECT B.id, B.account_number AS `account_number`, B.sortcode AS `sortcode` FROM `banks` B WHERE B.accountID = '". $this->account_id ."' AND B.status = '1'"); $this->data['banks'] = $query->result(); $this->load->view('_template/header', $this->data); $this->load->view('account/upload', $this->data); $this->load->view('_template/footer', $this->data); } What is not working properly? 1. The form is submitted 2. Form Validation Occurs 3. Transaction is recorded to the Database 4. Account information is updated with the transaction amount 5. Navigation change to account page 6. Query for Cards 7. Query for Banks 8. The view is then loaded for header, upload, and footer. I see that you perform: $this->load->view('account/upload', $this->data); So account/upload view has the needed code to parse that data array to display the information you want? So data['cards'] and data['banks'] would be used there. Quote Link to comment https://forums.phpfreaks.com/topic/286765-withdrawals-and-uploads/#findComment-1471799 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.