Jump to content

Recommended Posts

Using: Apache, php & mySQL.

 

 

Background Information

 

I have a database "movielibrary" which contains a table "movies" which has information of all the movies that I own. For each movie, I have stored the following fields:

 

"movie_id" (primary key, unique int)

"title" (varchar)

"year" (int)

 

I generated a random 3 digit integer between 1 and 218 (because 218 is the movie_id of my last entry in the movies table). Using this, I can generate a search string to query IMDB (using a different php app, which is not in question and works perfectly) and display the box shot and other information taken from the IMDB web site.

 

The search string that I generate is in the following format:

Example Search String for "King Kong (2005)" = "King+Kong+%282005%29" (without any quotes).

 

The string is generated by querying the mySQL database for the title and year that match the movieID that is the same as the randomly generated 3 digit number and is then stored in $searchString.

 

 

 

The problem:

 

In my program, the function that performs the search from IMDB and then stores the resulting movie information is called as follows:

 

$search = new imdbsearch ();

$search->setsearchname ($_GET['name']);

$results = $search->results ();

 

and then we can display the imdbID, the title and year from imdb in the following way:

 

foreach ($results as $res)

{

echo $res->imdbid();

echo '<br />';

echo $res->title();

echo '<br />';

echo $res->year();

}

 

This will work fine if I run the program by passing a search string value for GET myself in the URL:

 

http://localhost/MovieLibrary/randommovie.php?name=King+Kong+%282005%29

 

However, the way I want to do it is by passing my generated searchString because I don't want to manually have to put it in the URL. So the line that is in Red above is changed to:

 

$search->setsearchname ($searchString);

 

And this doesn't work...

 

What type of object is being passed in $_GET['name'] because it definitely isn't a String because if I try to pass a String to the function that performs the search it won't give me anything back. But when I pass it a $_GET object it works like a charm.

 

I need to pass it my $searchString object which is a String.

 

Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/83209-_get-and-strings/
Share on other sites

ah i mentioned it above. its a String which contains the generated search string which I want to use when calling the setsearchname method instead of using $_GET['name']

 

it is done in the line:

 

$search->setsearchname ($_GET['name']);

 

the program works fine if i manually put in the URL a value for name like:

index.php?name=KingKong

 

put if i put a string value KingKong in $searchString and call the function like this:

 

$search->setsearchname ($searchString);

 

...it wont work.

 

so my question is... what kind of object is $_GET['name'] and how can i convert my String object to be that kind of object.

Link to comment
https://forums.phpfreaks.com/topic/83209-_get-and-strings/#findComment-423303
Share on other sites

Don't encode it in the variable you create. PHP decodes all the GET variables and therefore you do not have e.g. %20 instead of a space in GET queries.

 

I.e. make $searchString = 'King Kong (2005)'; instead.

 

so my question is... what kind of object is $_GET['name'] and how can i convert my String object to be that kind of object.

Just a regular associative array, not an object (nor is your string an object).

Link to comment
https://forums.phpfreaks.com/topic/83209-_get-and-strings/#findComment-423322
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.