|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Foldin' For PCMech!
|
PHP search wildcard?
I'm working with a database and have the option to select between 8ish different groups to search from. For example: CPU Speed, CPu Type, RAM, OS, etc. how would I set it up so that a user might select all items from a specific group? Like so he can select a 2.8 P4 and with any amount of ram or something.
Its like when your searching on a website and have a drop down menu and you can select "Any" or "All" from the menu and get everything. How do you do this? thanks! |
|
|
|
|
|
#2 |
|
Chop Chop
|
What is the field type for each of the section? Like is the CPU TEXT and the amount of Ram INT? You could try to make them all TEXT, so numbers and letters can go into the field. Then tou should be able to have the "All" option. Are you just going to be displaying somewhere, or what?
|
|
|
|
|
|
#3 |
|
Foldin' For PCMech!
|
In the database or in the form? Everything is TEXT in the database. How do I use the "All" option? Yes, I want to have the data displayed on another page.
|
|
|
|
|
|
#4 |
|
Wx geek
Join Date: Aug 2005
Location: Indiana
Posts: 6,638
|
Can't you just include "All" like any other menu item?
__________________
"It is the way of man to make monsters and it is the nature of monsters to destroy their makers." |
|
|
|
|
|
#5 |
|
Foldin' For PCMech!
|
Thats what I want to do, but what do I set the value to so that it will include everything rather than search for the term "All".
|
|
|
|
|
|
#6 |
|
Wx geek
Join Date: Aug 2005
Location: Indiana
Posts: 6,638
|
Oh...I think for MySQL DB's you want to use %
|
|
|
|
|
|
#7 |
|
Foldin' For PCMech!
|
Ok, thats what I finally figured out after about 2 hours on google, but I can't get it to work. I think its because the way I am calling it in.
This is how its setup. I have a page with drop down menus and each option on the menu is assigned to a string, or whatever its called in PHP (i'm very new to it), and then sent to a search page when the data is searched for and displayed on screen. I set it up so that it would display what its searching for so I could tell if the right data was being passed. It shows that it is searching for the item "%" and not its wildcard value. |
|
|
|
|
|
#8 |
|
Wx geek
Join Date: Aug 2005
Location: Indiana
Posts: 6,638
|
OK, I think I see the problem. If you are setting All equal to "%" in say the variable $ram, then you do your query:
$query = "SELECT ram WHERE ram = '" . $ram ."'; Then what's happening is it's literally looking for '%'... not sure how to go about fixing that, but I think that's what's happening |
|
|
|
|
|
#9 |
|
Foldin' For PCMech!
|
from selection page:
Code:
select name="Sram" option value=% selected - RAM AMT - option Code:
$ query = "SELECT * FROM WU2 WHERE ram LIKE '$Sram' && client LIKE '$Sclient' && speed LIKE '$Sspeed'"" EDIT: i had to remove a few "< and >" so the text would show rather than the code running Last edited by enhanced08; 11-12-2005 at 08:50 AM. |
|
|
|
|
|
#10 |
|
Wx geek
Join Date: Aug 2005
Location: Indiana
Posts: 6,638
|
Have you tried something like this:
$query = "SELECT ram WHERE ram = '" . $ram ."'; I'm not really an expert at this, so... |
|
|
|
|
|
#11 |
|
Foldin' For PCMech!
|
nope, doesn't work...
should i keep option value=% or change it to something else? EDIT: I know there is a way to do this because I have seen it done before as I'm sure you have as well. Last edited by enhanced08; 11-12-2005 at 09:02 AM. |
|
|
|
|
|
#12 |
|
Wx geek
Join Date: Aug 2005
Location: Indiana
Posts: 6,638
|
Have you tried searching by literally 'ram = %', and not using a variable?
|
|
|
|
|
|
#13 |
|
Come in Ray...
Join Date: Sep 2004
Posts: 1,668
|
You said you have everything in the database set as TEXT? The wildcard search probably will not work unless you are indexing the field. Change the field type to VARCHAR and it should work.
|
|
|
|
|
|
#14 |
|
Staff
Premium Member
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
|
Need to modify things a bit.
PHP Code:
You are searching for the word 'them'. The above statement would find words like 'them', 'theme', 'anthem', if they existed in the field that you are searching. Course pretty silly to have RAM as a text field when it is numeric.
__________________
Want to Make $$$$ with your Computer? No Risk! Simply press shift-4 four times in a row |
|
|
|
|
|
#15 |
|
Foldin' For PCMech!
|
Ok, I got it to work, it turns out that I do have it set as VARCHAR rather than TEXT, sorry about that.
Thanks for the help guys, I hope your good at this stuff, cause I know I'll be back with more problems and questions! lol thanks! |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|