k_4f Posted December 26, 2007 Share Posted December 26, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/83209-_get-and-strings/ Share on other sites More sharing options...
Ken2k7 Posted December 26, 2007 Share Posted December 26, 2007 uh... what? I'm lost as to what your problem is. What's $searchString? It's not defined in the code? :S Quote Link to comment https://forums.phpfreaks.com/topic/83209-_get-and-strings/#findComment-423291 Share on other sites More sharing options...
k_4f Posted December 26, 2007 Author Share Posted December 26, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/83209-_get-and-strings/#findComment-423303 Share on other sites More sharing options...
Daniel0 Posted December 26, 2007 Share Posted December 26, 2007 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). Quote Link to comment https://forums.phpfreaks.com/topic/83209-_get-and-strings/#findComment-423322 Share on other sites More sharing options...
k_4f Posted December 27, 2007 Author Share Posted December 27, 2007 wow thank you, that worked perfectly to think i spent so many hours going down the wrong path thanks again. much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/83209-_get-and-strings/#findComment-423802 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.