Page 1 of 1
Help with fetching and returning PHP results.
Posted: Tue Jan 26, 2010 10:29 am
by alex.saidani
I am attempting to develop a PHP search engine that fetches results from a MYSQL database, however i am struggling on getting the search engine to fetch results from the database, i'm not sure how you do that. If anyone could offer any help or code to help with this that would be great
Also i am developing another PHP search engine that when you type the name of a film it will fetch and return a random result from the database that is in the same category as the film typed in, i hope to get it to forward to another page with the result on that page. If anyone can offer any help or code with this too that would be most appreciated.
Thanks in advance

Re: Help with fetching and returning PHP results.
Posted: Tue Jan 26, 2010 10:42 am
by JakeJ
Your inquiry is a little vague. What specifically are you having trouble with? Is there a particular piece of code that isn't working right or you don't even know where to begin?
Please try to be a little more specific. No one here is going to build your search engine for you so give it your best shot and we'll help you through the trouble spots.
Here's some questions for you to answer:
1. Do you know how to use php to connect to your database?
2. Do you know how to write a query in php to extract results from your database?
3. Do you know enough about databases to understand the general structure so that you know the right questions to ask?
4. If the answer to all of the above is yes, have you done so with the database you're trying to write the search engine for as a test? Extract some basic results, see what that gets you and then refine from there.
Re: Help with fetching and returning PHP results.
Posted: Tue Jan 26, 2010 4:21 pm
by alex.saidani
I know sorry about that, my actual problem is i dont know what the code is for being able to take a random result from a certain row in my database and retrieve it so it can be show on another page. I can pretty much do all of those things, i cant do the querys in PHP very well though. Any help with the bits of code for that would be great. Thanks for your reply though

.
Re: Help with fetching and returning PHP results.
Posted: Tue Jan 26, 2010 6:21 pm
by JakeJ
if you're using phpMyAdmin to control your database, when you execute a query, you should see, off to the right under the SQL you just issued an option to generate php code.
But if you want to select a random value out of your database try this: SELECT random(field) FROM table LIMIT 1
That returns one random result from a particular field. Obviously adjust the field name and table name to your needs.
To generate that in sq, it's nearly the same: $randomresult = mysql_query("SELECT random(field) FROM table LIMIT 1");
When injecting a php variable in to a query, do the following: $qry = mysql_query("SELECT * FROM table WHERE id = '$id' ORDER BY id");
If you're injecting a php variable from an array of some sort or from a form, do the following: $qry = mysql_query("SELECT * FROM table WHERE id = "$results[id]' ORDER BY id");
Note that when using that same variable referenced in php NOT in a query would be $results['id']
I hope this helps.