-1

I want to create a dynaic page, I have created model and controller and also data subitted in database successfully. Now, i'm having problem while displaying that data on front end.

Here is my Modal:

function getcorporate(){
    $q="SELECT * from corporate"; 
    $query=$this->db->query($q);
    return $query->result_array();
   }

Here is my Controller:

function corporate()
    {

        $popular['popular'] = $this->auth_model->getPopularcourses();
        $data1['corporate'] = $this->auth_model->getcorporate();
        $data["institute_details"] = $this->auth_model->getInstitutedetails();
        $data1['course'] = $this->auth_model->getcoursesdetailes();
        $this->load->view('nulearnFront/header', $data);
        $this->load->view('nulearnFront/corporate', $data1);
        $this->load->view('nulearnFront/footer', $popular);
    }
Hemant
  • 15
  • 5
  • 3
    Could you please edit your post to describe the expected result as well as the current result you're getting? – Teh Sep 10 '19 at 08:59
  • I think you should use `result()` instead of `result_array()`. – Hasitha Jayawardana Sep 10 '19 at 09:18
  • i'm trying to ask about view page code help. how do i get data publish on view page. – Hemant Sep 10 '19 at 09:23
  • Possible duplicate of [Codeigniter: Passing data from controller to view](https://stackoverflow.com/questions/9446700/codeigniter-passing-data-from-controller-to-view) – Teh Sep 10 '19 at 09:38
  • i used `` to print title from database in view, not worked – Hemant Sep 10 '19 at 09:44
  • 2
    `not worked` - what does it mean? Do you see errors? Something else? Describe your problem. – Don't Panic Sep 10 '19 at 10:52
  • I think you should see and learn how to ask show us you view page how many data do you want to display if you there are a lot of way to display data to view page – Nurbek Boymurodov Sep 10 '19 at 11:16

4 Answers4

0

Try this

First you can print_r() the data you receive.

print_r($corporate);

After that you can use foreach to display all the data

foreach($corporate as $value)
{

////do code according to your requirement

}

I hope this may be help out to solve your problem

Vintage Coders
  • 162
  • 1
  • 4
0

You are so close to the answer. You are passing the data from your Controller class. So what you have to do is just get that data as the follows,

I get the corporate values as it is returning an array data. So here you go,

In your view.php file,

<?php
    if (isset($corporate)) { // Check if the data is set or not
        foreach ($corporate as $corporateData) {
            ?>
                // Your HTML goes here, table or etc.

                <?php echo $corporateData->databaseColumnName // Value that need to print from the database ?>
            <?php
        }
    }
?>

Hope this helps you.

Hasitha Jayawardana
  • 2,326
  • 4
  • 18
  • 36
0

Add View file this code

<?php
    if (isset($corporate) && !empty($corporate)) {
        foreach ($corporate as $cdata) {

        echo $cdata->YourValue(db column name);

        }
    }
?>
0

print the query and run it to check

function getcorporate(){
    $q="SELECT * from corporate"; 
    $query=$this->db->query($q);
    print_r($this->db->last_query());die();
    return $query->result_array();
   }

if query works fine then you can foreah the query

foreach($corporate as $corporate)
        {
            echo corporate;

        }

if it does not return result then change result_array() to result() in model

Nooha Haris
  • 41
  • 1
  • 4