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

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:

MODEL:

   function estrai($search)
{

$query= $this->db->select('*')
->from('western')
->where('anno')
->like('anno', '$search')
->get();
return $query->result();
}

VIEW:

    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:

/index.php/home/mostramodulo?search=Ford&search=


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)
   
Reply
#2

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');
    exit();

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


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 )
Reply
#3

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

I would try to replace 

PHP Code:
->like('anno''$search'

with

PHP Code:
->like('anno'$search
Codeigniter 4 - Docker Image [github] [docker hub]
Reply
#4

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

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:
Code:
<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" />
</form>
</div>
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')
            ->select('*')
            ->like('title'$terms)
            ->orLike('origtitle'$terms)
            ->orderBy('year''title''desc')
            ->get();

        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');
        $count->like('title'$terms);
        $count->orLike('origtitle'$terms);
        $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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB