Building a message box for database query output
I am currently building several pages on my Website that will show the visitor my DVD collection so that they may request to borrow some (this is for friends and family). I have several .cfm pages built including movietitle.cfm, genre.cfm, mainactors.cfm, and parentalrating.cfm. The question I have is how to code in Coldfusion a message box to appear for the lookup of a certain movie title or actor that does not exist in the database or is misspelled. Does anyone know how to do this in ColdFusion?
openmind posted this at 22:38 — 15th May 2004.
He has: 945 posts
Joined: Aug 2001
Use an sql query to try and match the words so
SELECT *
FROM table
WHERE actor LIKE '%#searchPhrase#%'
and then just output the results:
#actor#
cgacfox posted this at 22:53 — 15th May 2004.
She has: 15 posts
Joined: May 2004
Here is the code that is on the main page for looking up info.
Enter name of the Actor that you are interested in seeing.
Does your example code go on the mainactors.cfm page?
Here is the code for the mainactors.cfm page for the output information as it currently is.
Select *
From DVDS
WHERE mainactors LIKE '%#FORM.mainactors#%'
Order by MovieTitle
Here is the code that will display the results of the query on the mainactors.cfm page.
#movieTitle#
#genre#
#parentalRating#
#mainActors#
I want a pop up message box to show that the query does not result in any matches either because it is not present or it is misspelled. Am I making sense? Thanks.
Cori
openmind posted this at 08:51 — 16th May 2004.
He has: 945 posts
Joined: Aug 2001
Thats pretty stright forward to do. Just change your code as follows:
First you need to do a quick count of how many results were obtained.
If none do the pop up. If more than 0 then show them...
<script language="javascript">
alert("Your search has resulted in no matches. Please try again");
history.go(-1);
</script>
#movieTitle#
#genre#
#parentalRating#
#mainActors#
To be honest you are better off not using the popup because it would look smoother just to write the text "no matches" or whatever rather than stick it in a pop-up...
cgacfox posted this at 20:44 — 16th May 2004.
She has: 15 posts
Joined: May 2004
Thank you very much. This works!! Now I can go on to the next step, which is using a data entry form online to add more movies. I am having some difficulties with this one as well. I will play with it some more and if I need help I will definitely come back here for some pointers. Again thank you!!
Cori
openmind posted this at 21:15 — 16th May 2004.
He has: 945 posts
Joined: Aug 2001
OK no problem
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.