Welcome to Questionaries, where you can ask questions and receive answers from other members of the community.

Let us know at info@questionaries.org

MySQL & PHP Searching a table

7 like 0 dislike
I want to be able to search through a MySQL table using values from a search string, from the url and display the results as an XML output.

I think I have got the formatting and declaring the variables from the search string down.

The issue I have is searching the entire table, I've looked over SO for previous answers, and they all seem to have to declare each column in the table to search through.

So for example my database layout is as follows:
[CODE]
**filesindex**
-filename
-creation
-length
-wall
-playlocation
[/CODE]
First of all would the following be appropriate:
[CODE]
$query = "SELECT * FROM filesindex WHERE filename LIKE '".$searchterm."%'
          UNION
          SELECT * FROM filesindex WHERE creation LIKE '".$searchterm."%'
          UNION
          SELECT * FROM filesindex WHERE length LIKE '".$searchterm."%'
          UNION
          SELECT * FROM filesindex WHERE wall LIKE '".$searchterm."%'
          UNION
          SELECT * FROM filesindex WHERE location LIKE '".$searchterm."%'";
[/CODE]
Or ideally, is there an easier way that involves less hardcoding to search a table.

Any ideas?

Thanks
asked 2 years ago by eagle09 (95,490 points)

Your answer

Email me at this address if my answer is selected or commented on:
Privacy: Your email address will only be used for sending these notifications.

0 Answers

Related questions

7 like 0 dislike
1 answer
2 like 0 dislike
0 answers
7 like 0 dislike
0 answers
asked 2 years ago by eagle09 (95,490 points)
6 like 0 dislike
0 answers
asked 1 year ago by eagle09 (95,490 points)
9 like 0 dislike
0 answers