Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFIF Variable is Empty 1

Status
Not open for further replies.

TamedTech

IS-IT--Management
May 3, 2005
998
GB
Hello Chapps,

I have the following CFQuery at the top of my document.

Code:
<CFQUERY NAME= "content" DATASOURCE= "managem6">
SELECT * FROM page_content WHERE id = "#ID#"
</CFQUERY>

The variable #ID# has been submitted from another .cfm file, my question is that if there is no #ID# variable submitted i want it to use the value of "1" as the "ID".

Thanks for your help,

Rob
 
if it has been submitted form another .cfm file, then it's probably a FORM variable, right?

<CFPARAM NAME="FORM.ID" DEFAULT="1">
<CFQUERY NAME= "content" DATASOURCE= "managem6">
SELECT * FROM page_content WHERE id = #FORM.ID#
</CFQUERY>

no quotes around the value in the SQL

r937.com | rudy.ca
 
Thanks for that buddy, I moddified your suggestion slightly so it fits in with my requirements, maybe you can offer me some afvice on whether i'm tackling this solution the right way.

Basicly i want to dynamicly drive the content of a site, including the nav from a database.

so i have index.cfm which displays all my content, and basicly all the hyperlinks link back to somthing like index.cfm?id=1 or id=2 or id=3 ... dependant on the content i want to diplay.

but the first time the user visits the index.cfm file, and it doesnt have the ?id=1 after is your recieve an error, so i now use this slightly modified version of your code

Code:
<CFPARAM NAME="ID" DEFAULT="1">
<CFQUERY NAME= "content" DATASOURCE= "managem6">
  SELECT * FROM page_content WHERE id = "#ID#"
</CFQUERY>

Is this way i can just add a row into my database table and it will add the content to my site ... quick and simple!

Is there a better way of doing this? i'm new to CF but this was the best method i could concoct.
 
okay, it appears your previous .cfm page doesn't use a form, but rather uses a parameter in the url scope

so what you need is

<CFPARAM NAME="URL.id" DEFAULT="1">
<CFQUERY NAME= "content" DATASOURCE= "managem6">
SELECT * FROM page_content WHERE id = #URL.id#</CFQUERY>

by the way, is ID numeric? if so, no quotes around the value in the SQL

r937.com | rudy.ca
 
ID is text at the moment so i kept the "" in.

I'll add that URL so i dont get spoof address sending in information? is that right?.

It's all working now, Thanks for your help buddy, purple star for effort!

Rob
 
put the cfparam tag in your application.cfm or .cfc with the default value for the first time visitor to the home page.

 
Yeah it is unusual to have the ID as text, its actualy a numeric value, just uses a "text" field.

I'm only playing around at the moment with learning CF, and my SQL is pretty sketchy too ... but once i have the basic process's figured out for the app then i'll put alot more thought into planning the database properly.

Thanks for your advice guys,

Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top