Skip to main content
Inspiring
June 11, 2008
Question

Query Questions

  • June 11, 2008
  • 7 replies
  • 898 views
Hello all,
I am trying to pull out information from the database based on what a link is passing. But I am pulling out information I don't need.

Here are my links:

cad1.cfm?headmodel=14

cad1.cfm?headmodel=14V

And the Query:

<cfquery name="getforce" datasource="mydb">
SELECT * FROM presses WHERE model_head LIKE '#headmodel#%'
</cfquery>

Now my problem is that I need only the results with a V in it to come up when using that link and vice versa. But they come up when using the link without the V as well.
This topic has been closed for replies.

7 replies

Inspiring
June 12, 2008
Your task would be so much easier if you normalized your db.
brianismAuthor
Inspiring
June 12, 2008
Anything is possible. Here is what a portion of the database looks like. It is MS Access.

My hardcoded links to choose either 14...whatever or 14v...whatever

cad1.cfm?headmodel=14

cad1.cfm?headmodel=14V

Then to the action page with the query:

<cfquery name="getforce" datasource="mydb">
SELECT * FROM presses WHERE model_head LIKE '#headmodel#%'
</cfquery>

And a link to the database design of it.

<a href=" http://i20.photobucket.com/albums/b218/indigobluedreamz/db.jpg">Click Here</a>



Inspiring
June 12, 2008
It's possible that you have a bad plan and/or a bad database design. However, there is not enough information to tell.

Will these url variables eventually be coming from an anchor tag or a form field where the method = get?
Inspiring
June 12, 2008
Let's rephrase that question. Are these url variables hard coded? Are they query results? Are they random strings?
brianismAuthor
Inspiring
June 12, 2008
Hi Dan,
These are just hard coded variables.
Inspiring
June 11, 2008
exactly how are these url variables being generated anyway?
brianismAuthor
Inspiring
June 12, 2008
quote:

Originally posted by: Dan Bracuk
exactly how are these url variables being generated anyway?


Well, I am just putting the "cad1.cfm?headmodel=14" as a link so when you click it the query pulls out results according to what the headmodel equals. That's where I'm running into the problem, because I don't know what to put to just bring out 14's or 14v's. There is always going to be things after the 14 or 14V Ex. 14F or 14VFR.
Inspiring
June 11, 2008
Your logic problem is that you are not using wildcards. Performance wise, you should scope your variables and use cfqueryparam.
Participating Frequently
June 11, 2008
Setting headmodel=14 should give you results both with and without the V, and headmodel=14V should include only those with the V. Is that what you are getting?

Phil
brianismAuthor
Inspiring
June 11, 2008
quote:

Originally posted by: paross1
Setting headmodel=14 should give you results both with and without the V, and headmodel=14V should include only those with the V. Is that what you are getting?

Phil



That is correct. What I need is setting headmodel=14 to not bring up any results with the V. I don't know how to do that.
Participating Frequently
June 11, 2008
quote:

What I need is setting headmodel=14 to not bring up any results with the V. I don't know how to do that.
Then your query should look more like this:

SELECT * FROM presses WHERE model_head = '#headmodel#'

Of course, when using = instead of using LIKE with wildcards (%), the value in #headmodel#' must match exactly with the values in the model_head column.

Phil