Results 1 to 5 of 5

Thread: [RESOLVED] List contents of MySQL database.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    Resolved [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.

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    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.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    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.

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2008
    Posts
    1,754

    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
  •  



Click Here to Expand Forum to Full Width