Here’s the special discount link for Rob’s course: http://johnmorrisonline.com/cwdc Check out my web developer resources here: …
source
Here’s the special discount link for Rob’s course: http://johnmorrisonline.com/cwdc Check out my web developer resources here: …
source
26 responses to “A PHP Script to Search a MySQL Database”
nice
What algorithm is used here(I mean like binary search, depth first search etc)? I want to know the algorithm. Thanks
if i want to search and download pdf through this ?
Hi John, I love this video and I hope you can help me take it a step farther; what if we wanted our search results to come back as a dynamic link that could be clicked and generate a new page that has more information on what you searched? Cheers
I have to search 700k records in another table for an 9digits member id , how do I do that ? what will be MySQL query for that ?
I WANT TO MAKE SEARCH OF Q AND ANS IN PNG FORM
error occurs. I'm sure there are no any typo mistakes. Checked the codes twice.
Warning: Missing argument 1 for search::search(), called in /my/directory/index.php on line 4 and defined in /my/directory/class-search.php on line 13
Fatal error: Call to a member function real_escape_string() on a non-object in /my/directory/class-search.php on line 14
Does anyone know the fix?
Hi John. Thank you for this video and script. I have used it, its really good. I like the way it is developed using OOP. Its a great script. The best i found so far to support a PHP search script i was looking for. I had 2 notice messages which i resolved, realising the 2 variables were not yet being processed until form submission. I also modified the script to add in a user message, should a search query return no results. I did this by adding an echo statement into the > if statement, > ! $query->num-rows, before the > return false; statement. I echo a message into a <div> tag, which i can then target on my front end using maybe Jquery append(). The only question that i have about the whole script is regarding the search form itself and the, Input type > search, and the > "value" parameter. What is the reason for echoing the > Search Term, back into the > "value" within the search input. Could you explain the reason for that ? I was able to remove the "value" from the input type, if its not necessary, but i'm trying to understand what the reason for it may be. It would be great if you could just clarify this. Its the only part that's left me scratching my head. Thanks again for such a great script.
I'm getting the following errors when I pull up the "search.php" in Chrome. I just get an HTTP 500 error when I open in IE.
PHP Notice: Undefined variable: search_term in on line 32
PHP Notice: Undefined variable: search_results in on line 37
I'm using MS Webmatrix to write the actual code, and I created my database on Wamp. I'm relatively new to PHP so any help or suggestions would be greatly appreciated.
Hi, how would this handle millions of rows of data? pls reply
Excellent tutorial and code – very easy to follow. I have adapted and changed the functionality a little. Results to a DataTable, etc. One thing I haven't figured out – how would you add a "no results" message? I'm looking at the "if ( ! $query->num_rows ) {
return false;" block, but so far all my attempts haven't worked.
I get: undefined variable search_term, and, undefined variable search_results
Hi, I'v got this error " Use of undefined constant FILE – assumed '_FILE_ ". i checked everything, but nothing is missing!
Undefined variable: search_results on line 33
Can also output the location, so in what table you found it? because I search multiple tables for a result and I would like to know the table name in which is the Result located
Tried this on database with 27000+ rows. Works in a fraction of second!
Thanks 🙂
Hi,
I have a problem with your code. I don't get the results olny the count and the array at the bottom but no results. I see everthing it that array, so the results are not listed why?
First I want to thank you for a great instruction video. It's close to what I want to achieve on a section of my own web page, though I'm trying to tweak it a bit to my own purposes, even if I'm next to a total php-noob.
Quick question: I want my list of results to display data from a different db column from the one I'm searching in, for instance I want to search in a "Country"-column, but have the results listed as corresponding titles from a "Titles" column. What part of the code do I need to change and how?
All I want to see is the result such as:
[routing_number] => 012345
[document_type] => Petition for Degrees
[document_desc] => Testing uploading an image of this document
How can I omit this:
Array
(
[count] => 3
[results] => Array
(
[0] => stdClass Object
(
[routing_number] => 012345
[document_type] => Petition for Degrees
[document_desc] => Testing uploading an image of this document
)
[1] => stdClass Object
(
[routing_number] => 123456
[document_type] => Invitation
[document_desc] => Testing uploading images to this document
)
[2] => stdClass Object
(
[routing_number] => 456789
[document_type] => Invitation
[document_desc] => This is to test uploading of image of the document
)
)
)
How to add dynamic hyperlinks for each result? Suppose, clicking one result will take me to a certain product page . Please Help !!
just a quick question, why have you opted for the object oriented style whereas in earlier tutorials you were using the procedural style to write a code?
BTW great video again 😛
i have tried out the code however all i am getting is a blank page
Can someone please help me resolve this error when I run the class search form
Notice: Trying to get property of non-object line 58
// Check results
if ( ! $query->num_rows ) {
return false;
}
Thank You
+John Morris I tried expanding upon the query in the "search" class to look for the search terms in multiple tables of my database like so:
SELECT *.files, *.users
FROM files, users
WHERE username LIKE '%{$sanitized}%'
OR name LIKE '%{$sanitized}%'
OR file LIKE '%{$sanitized}%'
OR title LIKE '%{$sanitized}%'
OR author LIKE '%{$sanitized}%'
OR description LIKE '%{$sanitized}%'
OR category LIKE '%{$sanitized}%'
OR keywords LIKE '%{$sanitized}%'
OR bio LIKE '%{$sanitized}%'
But I get the error: Notice: Trying to get property of non-object
Not all columns are in both tables and if I limit the query to one table, say the files table, and remove the OR statements for columns that are not found in the files table, it works as expected.
How can I expand upon this to search in multiple tables?
I'm a complete noob when it comes to PHP so I would like a little help here. I'm using your code that you provided, which part of the code to I change to that it pulls information from the database I created on phpMyAdmin?
can you do a script that will search the MySQL database image path row and return the image?