1

I am working on a call to the Youtube API. In this code the number of listings to return (maxResults) is set by the user through a form along with the search query. I want to set the maxResults myself and take away that choice from the user. In this piece of code, how can I set the maxResults to "30" instead of the $_GET['maxResults']?

 $searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
));

Thanks!

1
  • 1
    how about replacing $_GET['maxResults'] with 30..? Commented Aug 26, 2014 at 17:11

2 Answers 2

1

Cheers, try this codes my friend. And remember, always use "isset()" validation on super globals.

 $searchResponse = $youtube->search->listSearch('id, snippet', array(
     'q' => isset($_GET['q']) ? $_GET['q'] : null,
     'maxResults' => 30, //insert maxResult count here
));
Sign up to request clarification or add additional context in comments.

3 Comments

Set doesn't mean not empty.
He said he wants to NOT use the parameter from the user. This code just adds a default value.
Thanks lin - 'maxResults' => 30 works. I had an IF statement further up that checked if the parameter was set from user, preventing the this bit from executing in the first place - duh. Your isset comment helped me realize this. Cheers.
1
 $searchResponse = $youtube->search->listSearch('id,snippet', array(
 'q' => $_GET['q'],
 'maxResults' => 30,
 ));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.