Welcome Guest, Not a member yet? Register   Sign In
Problem with Codes
#1

This is the Big Problem which I believe I could have taken care of if I am a good codeigniter but very new to codeigniter
application\controllers I have this codings in her
PHP Code:
function debtor_print_viewNEW()
 
   {
 
       if ($this->session->userdata('admin_login') != 1)
 
           redirect('login''refresh');
 
       
        $page_data
['page_name' 'debtor_print_viewNEW';
 
       $page_data['page_title'] = get_phrase('debtor_print_viewNEW');
 
       $query $this->debtor_print_viewNEW();
 
       $this->load->view('backend/index'$page_data);
 
   }

 
   }
inside application\models I have this codes
function debtor_print_viewNEW( ) {
       $this->db->select("invoice.student_id as STUDENT_ID,student.name AS STUDENT_NAME,section.name  AS CLASS,invoice.description AS DESCRIPTION, invoice.amount AS TOTAL_AMOUNT, invoice.amount_owed  AS AMOUNT_OWED, parent.name AS PARENT_NAME, parent.email AS PARENT_EMAIL, parent.phone AS PARENT_PHONE, parent.address AS PARENT_ADDRESS,  invoice.status AS STATUS");
       $this->db->from('invoice ');
       $this->db->join('student  ''student.student_id = invoice.student_id');
       $this->db->join('parent ''parent.parent_id = student.parent_id, 'left'');
       $this->db->join('section  ''section.section_id = student.section_id','left');
       $this->db->where('invoice.status''debtor'); 
       $query 
$this->db->get(); 
       return $query
->result();
      

Inside View Block application
\views\backend\admin

foreach ($get_debtors as $row)
{
$i 0;
$max 25;
 if ($i == $max) or ($i == 0)
    {
        

        
//print column titles for the current page
        </center>
        <table style="width:100%; border-collapse:collapse;border: 1px solid #ccc; margin-top: 10px;" border="1">
        <tbody>
        <thead>
        <tr>
            <td style="text-align: center;">STUDENT ID</td>
            <td style="text-align: center;">STUDENT NAME</td>
            <td style="text-align: center;">CLASS</td>
            <td style="text-align: center;">DESCRIPTION</td>
            <td style="text-align: center;">TOTAL AMOUNT</td>
            <td style="text-align: center;">AMOUNT OWED</td>
            <td style="text-align: center;">PARENT NAME</td>
            <td style="text-align: center;">PARENT EMAIL</td>
            <td style="text-align: center;">PARENT PHONE</td>
            <td style="text-align: center;">PAREBT ADDRESS</td>
            <td style="text-align: center;">STATUS</td>
        </tr>
    </thead>
             
        
//Set $i variable to 0 (first row)
        $i 0;
    }
   $i += 1; 
   
<tr> 
    
echo '<td><div align="left">'.$row['STUDENT_ID'].'</td>';
    echo '<td><div align="left">'.$row['STUDENT_NAME'].'</td>';
    echo '<td><div align="left">'.$row['CLASS'].'</td>';
    echo '<td><div align="left">'.$row['DESCRPTION'].'</td>';
    echo '<td><div align="left">'.$row['TOTAL_AMOUNT'].'</td>';
    echo '<td><div align="left">'.$row['AMOUNT_OWED'].'</td>';
    echo '<td><div align="left">'.$row['PARENT_NAME'].'</td>';
    echo '<td><div align="left">'.$row['PAREBT_PHONE'].'</td>';
    echo '<td><div align="left">'.$row['PARENT_ADDRESS'].'</td>';
    echo '<td><div align="left">'.$row['STATUS'].'</td>'  
}

<?
php endforeach; ?>
?>     
Reply
#2

What is your question?
Reply
#3

(11-06-2016, 07:07 AM)Wouter60 Wrote: What is your question?

Is the code set out appropriately?  however,  it is not even doing anything after putting the Query Build in the Models  may be it's not being recognized.

 I am sure someone from this group might have encountered this problem in the past so my friend is it something you can help me with  help me walk through the program to see if I have done the right thing and point out my mistakes thanks and God Bless
Reply
#4

(This post was last modified: 11-06-2016, 03:41 PM by Wouter60.)

You're on the right track, but there are a lot of basic mistakes in your code.
It seems that you have a controller with a function named "debtor_print_viewNEW()".
But you also have a model with a function with the same name!
It's guaranteed that this will cause confusion.
I recommend renaming the model function to something like "get_debtors()", and the controller function just "debtors".
It's bad practice to use capital letters in function names.

Right now, the controller function is even calling itself, causing an infinite loop.
You have this inside the debtor_print_viewNEW() function:
PHP Code:
$query $this->debtor_print_viewNEW(); 

Where I think you should do this:
PHP Code:
$this->load->model('invoices_model');  //application/models/Invoices_model.php
$page_data['get_debtors'] = $this->invoices_model->get_debtors();  //call get_debtors function in Invoices_model.php 

Next, setup your model function without the join statements for a start. Just to make sure that it will return records from your database. You can extend later on.
PHP Code:
function get_debtors() 
{
 
  $this->db
   
->select('*')
 
  ->from('invoice')
 
  ->where('status''debtor'); 
 
  $query $this->db->get(); 
 
  return $query->result_array();   
  
//use result_array if you want to handle the result as an array in your view, like you are doing.
  

The controller loads a view with this name:
PHP Code:
$this->load->view('backend/index'$page_data);  //load view named application/views/backend/index.php' 

Make sure this view exists!
Reply
#5

(11-06-2016, 02:59 PM)Wouter60 Wrote: You're on the right track, but there are a lot of basic mistakes in your code.
It seems that you have a controller with a function named "debtor_print_viewNEW()".
But you also have a model with a function with the same name!
It's guaranteed that this will cause confusion.
I recommend renaming the model function to something like "get_debtors()", and the controller function just "debtors".
It's bad practice to use capital letters in function names.

Right now, the controller function is even calling itself, causing an infinite loop.
You have this inside the debtor_print_viewNEW() function:
PHP Code:
$query $this->debtor_print_viewNEW(); 

Where I think you should do this:
PHP Code:
$this->load->model('invoices_model');  //application/models/Invoices_model.php
$page_data['get_debtors'] = $this->invoices_model->get_debtors();  //call get_debtors function in Invoices_model.php 

Next, setup your model function without the join statements for a start. Just to make sure that it will return records from your database. You can extend later on.
PHP Code:
function get_debtors() 
{
 
  $this->db
   
->select('*')
 
  ->from('invoice')
 
  ->where('status''debtor'); 
 
  $query $this->db->get(); 
 
  return $query->result_array();   
  
//use result_array if you want to handle the result as an array in your view, like you are doing.
  

The controller loads a view with this name:
PHP Code:
$this->load->view('backend/index'$page_data);  //load view named application/views/backend/index.php' 

Make sure this view exists!
Thanks and God Bless I appreciate Ur efforts in helping out
Reply
#6

Wouter60,

Thank you so much here you will find the attached document is the changes made to the code but no out put yet

Thanks 
jay01

Attached Files
.docx   Program Coding.docx (Size: 14.18 KB / Downloads: 55)
Reply
#7

You say that there's no output yet. But CI (or php) must give you at least one or more error messages.
Solve these errors one by one.
If there are no errors any more, and you still get a blank page, I'm willing to help you further. No offence now, but your current approach is one where I'm building the web application for you, and that's not what I want. And it won't help you learn CodeIgniter.
Please, invest a few days in studying the documentation website. CI is not that difficult, but it's not a good idea to skip that and just start asking other people to help you.
Reply
#8

(11-07-2016, 11:46 AM)Wouter60 Wrote: You say that there's no output yet. But CI (or php) must give you at least one or more error messages.
Solve these errors one by one.
If there are no errors any more, and you still get a blank page, I'm willing to help you further. No offence now, but your current approach is one where I'm building the web application for you, and that's not what I want. And it won't help you learn CodeIgniter.
Please, invest a few days in studying the documentation website. CI is not that difficult, but it's not a good idea to skip that and just start asking other people to help you.

Thank you very much Sir No error showed up. This is the only part of my program that is not working some time if I put the code like that it will tell me the host can not find this even my application that is working will not work at all 

 I have passed the stage that it gives out a 404 error I don't know what else to do  if you have a better documentation on codeigniter you can share with me please send it as a link it will be very helpful. 

Thanks and God Bless
Jay
Reply
#9

(11-06-2016, 07:03 PM)Jay01 Wrote:
(11-06-2016, 02:59 PM)Wouter60 Wrote: You're on the right track, but there are a lot of basic mistakes in your code.
It seems that you have a controller with a function named "debtor_print_viewNEW()".
But you also have a model with a function with the same name!
It's guaranteed that this will cause confusion.
I recommend renaming the model function to something like "get_debtors()", and the controller function just "debtors".
It's bad practice to use capital letters in function names.

Right now, the controller function is even calling itself, causing an infinite loop.
You have this inside the debtor_print_viewNEW() function:
PHP Code:
$query $this->debtor_print_viewNEW(); 

Where I think you should do this:
PHP Code:
$this->load->model('invoices_model');  //application/models/Invoices_model.php
$page_data['get_debtors'] = $this->invoices_model->get_debtors();  //call get_debtors function in Invoices_model.php 

Next, setup your model function without the join statements for a start. Just to make sure that it will return records from your database. You can extend later on.
PHP Code:
function get_debtors() 
{
 
  $this->db
   
->select('*')
 
  ->from('invoice')
 
  ->where('status''debtor'); 
 
  $query $this->db->get(); 
 
  return $query->result_array();   
  
//use result_array if you want to handle the result as an array in your view, like you are doing.
  

The controller loads a view with this name:
PHP Code:
$this->load->view('backend/index'$page_data);  //load view named application/views/backend/index.php' 

Make sure this view exists!
Thanks and God Bless I appreciate Ur efforts in helping out
You are a Codeigniter Guru indeed You are accurate I eventually came up with an error please see it below 
An Error Was Encountered

Unable to determine what should be displayed. A default route has not been specified in the routing file.

God Bless
Reply
#10

In your attachment, it looks like you name your controller "Controller.php". This is a recipe for trouble. Controller is a reserved name in CI for a specific type of class.
It's also very odd to address to a page on your website with a URL like www.mysite.com/controller/debtor_print_view, isn't it?
Rename the controller to Invoices.php. Don't forget to change the class name inside the controller too.

Your controller function starts with this line:
PHP Code:
$this>load>model('invoices_model'); 

It should be:
PHP Code:
$this->load->model('invoices_model'); 

Next, in your controller, you are loading this view:
PHP Code:
$this->load->view('backend/index'$page_data); 

CI is looking for a view named application/views/backend/index.php.
But the view you mention in the attachment is named debtor_print_view.php. You can't expect your application to work that way.

Also, in your model, you have this line:

PHP Code:
$this->db->from('invoice '); 

Remove the space character after invoice, because the Query Builder will try to open a table named "invoice ", which most likely not exists.

Last but not least, your view has a bunch of wrong code. Remove all of it. Just put this in your view, to test if the controller passes the data correctly:
PHP Code:
<?php
echo '<pre>';
print_r($get_debtors);   //$get_debtors is passed by the controller via $page_data['get_debtors'];
echo '</pre>';
?>

Finally, run your application and call the url www.mysite.com/invoices/debtor_print_view
Reply




Theme © iAndrew 2016 - Forum software by © MyBB