Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get Movie/TV/Person search page ? #58

Closed
omar-elhamedy opened this issue Nov 14, 2018 · 2 comments
Closed

How to get Movie/TV/Person search page ? #58

omar-elhamedy opened this issue Nov 14, 2018 · 2 comments

Comments

@omar-elhamedy
Copy link

How to get the pages for search so I can connect it to my URL&page=(the number of the search page) ?
I tried to edit this part but I got an error and the same results when I passed the Page number? could you please help me with this ?

public function searchMovie($movieTitle,$page){

 	$movies = array();

 	$result = $this->_call('search/movie', '&query='. urlencode($movieTitle), '&page=' . $page);

 	foreach($result['results'] as $data){
 		$movies[] = new Movie($data);
 	}

 	return $movies;
 }

The Error

Warning: Invalid argument supplied for foreach() in ...\controller\classes\config\Configuration.php on line 48

Thanks

@iBringit
Copy link

iBringit commented Nov 15, 2018

you need to supply an array for foreach statement, instead you are requesting a key value..

try

foreach ($result as $data)

// then fetch the results here

remember $result returns an array you can fetch within the foreach statement as $ data

@omar-elhamedy
Copy link
Author

omar-elhamedy commented Nov 15, 2018

Hi @iBringit Thanks for your reply,
Please take a look at this code

// This is the code to get the page number from the URL
if(isset($_GET['page'])){
    $page = $_GET['page'];
} else {
    $page = 1;
}

if($page == '' || $page == 1){
    $page1 = 0;
}else{
    $page1 = ($page*10)-10;

}

//This is my code for the search

// and the $query is a _GET from the URL

$multiSearchResults = $tmdb->multiSearch($query);

foreach($multiSearchResults as $mediaType => $searchResults){
        foreach($searchResults as $searchResult) {
            if($searchResult->getMediaType() === 'movie') {
               echo" <div class='gridViewItem'>
                        <a href='/movies/movie?id=". $searchResult->getID() ."'><img class='backup_picture' id='poster' src='http://image.tmdb.org/t/p/original". $searchResult->getPoster() ."'></a>
                        <a href='/movies/movie?id=".$searchResult->getID()."'><div class='gridViewInfo'>"
                                . $searchResult->getTitle() .
                               "</div></a>


                        </div>";
            }}};

This code only show me the search result for the first page only from the API and I want to make a pagination on my website with each page show the results associated with the page number .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants