|
-
May 19th, 2009, 07:11 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] List contents of MySQL database.
Hello i have a mySQL database and in the database there is a table called products. Here is the order of columns in products:
"Title","Description","Seller","Picture","Qaulity","Price","Country","Province","City","School","Cam pus","Grade","Room"
I want the user to be able to search for the title and then all the rows found with the title the user specified will be displayed to the user in a table. When it gets to the Picture column i want it displayed in img tags. As well i need the table to display the information it gets in a different order. The picture will be the last column of the table etc..
When the user searches for the title it doesn't need to be an exact match for example:
Title = Book1
Search can be = Book
Last edited by noahssite; May 19th, 2009 at 07:18 PM.
-
May 19th, 2009, 07:27 PM
#2
Re: List contents of MySQL database.
Use the wildcard character %. The code below will search for anything with 'Book' in the title. (Example: 'Book of Music', 'Cook Book' and 'Dog Books')
Code:
SELECT FROM 'mytable' WHERE Title='%Book%'
I am assuming you already know how to use mysql functions in php. If not, check out the tutorial in my signature.
-
May 20th, 2009, 05:00 PM
#3
Thread Starter
Frenzied Member
Re: List contents of MySQL database.
I didn't have time yesterday to reply but i solved it on my own anyway. I didn't use wildcards instead i just added in an additional if statement containing: stristr() function. As well i used a While loop and SELECT FROM products WHERE Title=... to create a table.
-
May 20th, 2009, 06:02 PM
#4
Re: [RESOLVED] List contents of MySQL database.
that is a seriously bad way to filter results when dealing with a database. it might seem fast and efficient with a small table, but when you have hundreds or thousands of records you will notice how slow it is.
now, to use wild cards correctly, you need to use the LIKE operator (rather than "="). this will also always be a case insensitive search. you can build your SQL statement like so:
Code:
SELECT * FROM table WHERE title LIKE '%book%'
hope that helps.
-
May 23rd, 2009, 09:41 AM
#5
Thread Starter
Frenzied Member
Re: [RESOLVED] List contents of MySQL database.
Thank you i will probally replace my old means of filtering with that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|