[thelist] Doh! question for MySQL

walker walker at sdproductions.com
Wed Feb 14 01:10:17 CST 2001

Thanks Rudy,

I was hoping there was another way to do it, without having to query the 
table beforehand to find out the max row number of the table.

back to work. Do I owe a tip for this? I'll give one anyway.

<tip type="cold fusion & saved queries" author="walker">
If you have queries that should only be run once, and don't change for all 
users in your application (like a query that pulls the states for your 
contact form drop down list) - then save the entire query as an application 

For example:
in your application.cfm

(initialize the application variable)
<cfparam name="application.initialize" default="0">

(this is to make sure the query only runs once)
<cfif application.initialize is 0>

         (here is the query)
         <cfquery name="get_states" datasource="yourdb">
         select * from states

         (save the query)
         <cfset application.states=get_states>

         <cfset application.initialize=1>

then in your contact form (or elsewhere):

<select class="formbody" name="state">
<cfoutput query=application.states>
<option value=#state_id#>#state_name#</option> (where state_id and 
state_name are columns in the states table)

This also works with session variables - if you want to save all of the 
information about a user, etc....

For example, after a login has been validated:

         (here is the query)
         <cfquery name="get_user_info" datasource="yourdb">
         select * from users where user_id=#user_id#

         (save the query)
         <cfset session.user=get_user_info>

and then in your application:

You are logged in as: #session.user.username# (username can be swapped with 
any other column in the users table)


walker fenton
walker at sdproductions.com

More information about the thelist mailing list