Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8667905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:04:54+00:00 2026-06-12T18:04:54+00:00

I have one not understood point In MVC pattern. Please help understood. for example

  • 0

I have one not understood point In MVC pattern. Please help understood.

for example we have table for cars in database, we want obtain and print results from table, but if results are not found (0 rows), in this case print: “We dont have results”

this is models.php

class modesl {

function getCars () {

    $res = $this->db->query("SELECT names FROM cars");
    if ($res->num_rows == 0) {
        return "We dont have results";
    }
    else {
        return $res;
    }

}

}

this is views.php

class views {

    function loadHTML ($resultFromCars) {
         require 'carspage.php';
    }

}

this is carspage.php

<html>
<body>
<?php

    if (is_object($resultFromCars)) {
        while ($row = $resultFromCars->fetch_assoc()) {
            echo $row['names']."<br>";
        }
    }
    else {
        echo  $resultFromCars;
    }

?>
</body>
</html>

this is controllers.php

class controllers {

    function generatePage () {  
        $model = new models();
        $resultFromCars = $model->getCars();


        $view = new views();
        $view->loadHTML($resultFromCars);
    }

}

This works, but as I know, many php code in view, (that is condition if (is_object) { } else { } ) is not right MVC. tell please for this concret case, what must be change in my architecture (lol), for obtain right MVC concept?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:04:55+00:00Added an answer on June 12, 2026 at 6:04 pm

    You seem to have done a good job, just one small thing to improve. As the model is a wrapper for data only, so you should return only data (and no strings, containing error/exception messages). In the case there’s no data to return, then return FALSE, as it’s done in PHP.

    class CarModel {
    
        function getCars () {
    
            $res = $this->db->query("SELECT names FROM cars");
            if ($res->num_rows == 0) {
                return FALSE; // if that happens, the function will stop execution here, so no "else" is needed
            }
    
            return $res;
    
        }
    
    }
    

    And in your view

    <?php
    
        if ($resultFromCars === FALSE && !empty($resultFromCars)) {
            echo "We don't have results";
        }
        else { // now you know it's not FALSE, so it must be an object, no need to check whether it is one
            while ($row = $resultFromCars->fetch_assoc()) {
                echo $row['names']."<br>";
            }
        }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have 10 breakpoints and I want to clear one but not
I have one xsd file I'd rather not modify (Exceptions.xsd): <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema xmlns=http://me.com/Exceptions.xsd targetNamespace=http://me.com/Exceptions.xsd
I would like to have one column in QTableWidget NOT editable. In forums I
Suppose I have created one jQuery function to check if elements exist or not
I have an NSDictionary that holds all the data: One title (not important for
I have seen a few posts regarding this issue but not one specific to
I've read through a number of topics now and have not found one quite
I have been trying to find a solution to this one but could not
I need to ensure that a given field does not have more than one
I have a overridden UIGestureRecogniser designed to detect 2 touches, but not necessarily one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.