Welcome Guest, Not a member yet? Register   Sign In
WHERE-LIKE and problem for build search-engin in western movie web app

Mean thanks for allowing me to retrieve values in get with the statement $ search = $ this-> input-> get, I'm trying to use the same method for an internal search engine in my western film library but I can't find the key to the problem. In the Model di CI versione 3.0 I put:


   function estrai($search)

$query= $this->db->select('*')
->like('anno', '$search')
return $query->result();


    public function mostramodulo()
    $search = $this->input->get('search');
    $data['result'] = $this->western_model->estrai($search);
    $this->load->view('western/mostramodulo', $data);

I have a form with a text field and a submit which sends data on the text which has the name search. the information is sent correctly because in url I see:


but the result is a blank page so I tried to print the value in transit which should become $ search with ECHO but it confirms my doubts is that there is no value inside and therefore I cannot graphically build the page because the model does not work.

but when i try to view the page i see the message

Severity: Notice

Message: Undefined variable: search

Filename: western/mostramodulo.php

do you have any suggestions to be able to extract from the engine the name of a director or the year in which the film was shot with subsequent materialization of the data sought? Thanks for any tips, I'm at the beginning and not framed everything well, on the CI 3 documentation I did not find the use of the LIKE linked to WHERE clear to me

Attached Files Thumbnail(s)

Well it would help if you showed your code for the form also.

But what do you get when you use the code below?

PHP Code:
public function mostramodulo()
    $search $this->input->get('search');

    echo $this->input->get('search');

    $data['result'] = $this->western_model->estrai($search);

If it's blank then you are not receiving the value from your form, if you get a
value then the problem is in your model which we would need to see the code for that also.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

(This post was last modified: 10-31-2020, 05:57 PM by atsanna.)

I would try to replace 

PHP Code:


PHP Code:
Codeigniter 4 - Docker Image [github] [docker hub]

Thank you for sharing, help me have some more ways to fix the error.

I have a movie catalog and I believe I can help you, but I use CI4. As I only use queries, I believe it is possible for you to adapt them to CI3.
The method of sending the search argument I still use the same as used in CI3:
<div class="search-container">
<form action="/search/allmedia" class="site-search" method="post" name="site-search">
<input class="site-search-button" name="wdeda" type="submit" />
<input class="site-search-input" name="search" placeholder="Search" tabindex="1" type="search" />
I also have a music catalog from the movie catalog so the "form action is 'search/allmedia' where search is the controller and allmedia the method. This code is inserted in a header, used on every page.

Below the search code, I also show the number of results, in the search result. You can search by title, the one used in your country, 'title' and/or by the original title, 'origtitle'; 'terms' is the search argument coming from the form.
PHP Code:
  public function getMovies()
        $request service('request');
        $terms $request->getVar('search');
        $db $this->db;
        $query $db->table('movies')

        return $query->getResult();

$request is related to CI4

PHP Code:
public function numMovies()
        $request service('request');
        $terms $request->getVar('search');
        $db $this->db;
        $count $db->table('movies');
        $data $count->countAllResults();

        return $date;

As for directors, year, actors, etc. it will depend on how you created it or will you create a table for it. There is another important detail regarding data modeling. In addition to the "movies" table you should also have a "names" table and as the relationship between them is many to many, a third table should be created, relating both.

Theme © iAndrew 2016 - Forum software by © MyBB