View Full Version : Search/results problem, please help!
09-16-2004, 04:51 PM
I have a database with lots of names, and i'm having immense trouble trying to get a search page to query the database and send back the results.
I'm doing it all in Dreamweaver using PHP and the database is MySQL. I can display the database on a php page no problem, and make a form that inputs new names, but I can't for the life of me set up a search page, and have the searched name displayed from the db. All I keep getting is the whole db displayed instead of just the info I want.
Does anybody know of a good step by step tutorial to help me, or any advice to put me straight would be excellent and very much appreciated.
Thanks in advance!
09-16-2004, 05:59 PM
What is the query that runs to search for the name?
09-16-2004, 07:16 PM
SELECT FIRSTNAME, LASTNAME, YEAR STARTED, ETC FROM DBNAME WHERE LASTNAME LIKE 'varLastName' AND YEARSTARTED LIKE 'varYearStarted'
Thanks SteveF, i'm not at work so i've had to do this from memory, but the general jist of the search form is to aquire all database details about the person by submitting either last name and/or year started.
09-17-2004, 04:41 AM
The query needs looking at,
dont like the 'like'
if you want to find one record use =
and you need a Or not an "and"
But your first query should have not retrieved all the records each time, so make sure your form is loading the correct query - put a write statement to output your query to screen to check what is the current statement
09-17-2004, 06:34 AM
Not sure how to output the statement to screen....but the error message I get when i attempt to use the search form now is:
Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE or '$' in d:\web\results.php on line 6
This is the sql used:
SELECT FIRST_NAME, LAST_NAME, YEAR_STARTED, NETWORK_ACCESS, INTERNET_ACCESS, IMAGES
WHERE LAST_NAME LIKE 'varLastName' AND YEAR_STARTED LIKE 'varYearStarted'
Yesterday the whole database appeared, now all i get is the above error.
I changed AND to OR and the query brings back no results (within the Variables box 'test' button) so it seems to like the AND syntax.
I have had success with entering a letter in the Default Value and it brings back all sirnames starting with that letter, but if i enter a name that IS in the db it comes back saying 'no records'.
I hope this makes sense, if i can provide any more info just let me know.
09-17-2004, 07:14 AM
Is your yearstarted a text field or a number
If its a number you will have to change the query expression as its looing at a text field.
Still dont like the and
are you inputing both search items when searching or just one,
09-17-2004, 07:34 AM
yearstarted is a number, in the form as a drop down menu with the year variables ie 2001, 2002 etc.
The idea is to input name and/or date into the form. I have been testing by inputting one and both but I still get the same sparse error
09-17-2004, 08:03 AM
I just managed to get rid of the parse error by including a $ in the sql syntax on line 6.
The results page is now always displaying the first name in the db, but i can't get the results to display anything different. Any ideas?
09-17-2004, 08:19 AM
Make sure your form is loading the correct query - put a write statement to output your query to screen to check what is the current statement
(taking son back to Uni now will be back much later)
09-21-2004, 11:06 AM
Just a thought.
It looks like you are trying to use the advanced search screen with a dynamic variable that is set at run time.
I have been working with mysql and dreamweaver for about 6 months now. I'm trying to learn how to make all the parts work together. I also had difficulty using that screen to set a variable at run time.
The general problem that I had was that dreamweaver generated code that I didn't understand. I took a few steps back, bought a few books on php and mysql and learned how to generate the main database componenets by hand. I now can write code to add, edit, search and modify the db. As a result I now have a better understanding of how dreamweaver code works.
I would suggest that you try to get your mysql select statements to work from the command line. Once you have done that then write code manually to search the database and print it to the screen. After you do that you may have a better understanding of how to use dreamweaver to do it.
If you are interested I can send you basic php code to do simple search.
A different alternative would be to find a dreamweaver guru to tell you how to set up a search var using the advanced dreamweaver search screen.