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 8694755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:51:37+00:00 2026-06-13T00:51:37+00:00

Model $q = $this->db->get_where(‘person’, array(‘p_id’ => $p)); if($q->num_rows()!=1) { redirect(‘General_Area/Home’); exit(); } else {

  • 0

Model

  $q = $this->db->get_where('person', array('p_id' => $p));
  if($q->num_rows()!=1) 
    {
    redirect('General_Area/Home');
    exit();
    }
    else
    {   
         . . . 

Ok So once the model is initialized it queries the db and looks for exactly one match and if found it moves on the else statement. However if not found it will redirect('General_Area/Home');

How do I pass a message in there? In my controller I am returning an object if the query is successful.

And in my view i am echo obj->table_col_name

  $q = $this->db->get_where('person', array('p_id' => $p));
  if($q->num_rows()!=1) 
    {
    return $Error = 'You have not been found!...';
    #redirect('General_Area/Home');
    exit();
    }
    else
    {   
         . . .  

If the $q was not successful I want to be able to echo $error; in the view for the user to see the message.

  • 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-13T00:51:38+00:00Added an answer on June 13, 2026 at 12:51 am

    In your Model

    if($q->num_rows()>0)
    {
        return array('result'=>$q->result(), 'message'=>'This is a message');
    }
    return false;
    

    In the Controller

    $this->load->model('your_model_name');
    $data['query']=$this->your_model_name->model_function_name();
    if(!$data['query']['result'])
    {
        redirect('General_Area/Home');
        exit();
    }
    else $this->load->view('your_view_name',$data);
    

    In your View

    if(isset($query))
    {
        foreach($query as $row)
        {
            // code goes here to echo columns
        }
        //and message is available as $message so you can print it like
        if(isset($message)) echo $message;
    }
    

    Message on redirect

    Also if you want to send a message when you redirect to another page you can use in your controller

    if(!$data['query']['result'])
    {
        $this->session->set_flashdata('message', 'your message text here!');
        redirect('General_Area/Home');
        exit();
    }
    

    So you can print the message in the view like

    echo $this->session->flashdata('message');
    

    Read more about Flashdata.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Model $data = array(); $session_id = $this->session->userdata('id'); $q = $this->db->get_where('cust_orders', array('cust_id' => $id)); foreach
i have this model and configuration public class Person { public int? FatherId {
I have a trouble trying to get this working. I have an Item model,
I've got a model like this def upload_location(instance, filename): return 'validate/%s/builds/%s' % (get_current_user(), filename)
This is my model class [HiddenInput(DisplayValue = false)] public long ProductId { get; set;
My model class is like this: Public class abc { public string p1 get;
this is my core data model: I'm trying to get all LanguageEntries from a
I have this function in my model the purpose of it is to get
I'm trying to model this constraint in GMPL. As far as I can understand,
I am trying to model this relationship following this link http://www.javaworld.com/javaworld/jw-01-2008/images/datamodel.gif Its the usual

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.