473,324 Members | 2,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Looping over query details

Hi guys,

I don't know whether this is feasible or not. But here is my problem

I have a session variable which has database field names in a particular order and this variable is generated dynamically, I dont know what is in that variable and in what order. What I have to do is display my results in the order they are in the session variable. So for example if my session varialbe contains

session.sv = "Id,Name,Address,Phone,City,Location"

I am using this directly in my query as

select #session.sv# from details

And I want to display the records only in that particular order i.e Id, Name, Address, Phone, City and Location, this order is dynamic. So It can be City first, Address second etc...

Hope someone can tell me how to solve this issue.

Thanks in advance.
Sep 18 '07 #1

✓ answered by Shift4SMS

Just in case you need an example of what acoder was saying:

Expand|Select|Wrap|Line Numbers
  1. <cfset session.sv = "Id,Name,Address,Phone,City,Location">
  2.  
  3. <cfquery name="qResults" datasource="#ds#" username="#un#" password="#pw#">
  4.     select #session.sv# from details
  5. </cfquery>
  6.  
  7. <cfoutput>
  8.     <table>
  9.         <tr>
  10.             <cfloop index="fieldname" list="#session.sv#">
  11.                 <th>#fieldname#</th>
  12.             </cfloop>
  13.         </tr>
  14.         <cfloop query="qResults">
  15.             <tr>
  16.                 <cfloop index="fieldname" list="#session.sv#">
  17.                     <td>qResults[fieldname][qResults.CurrentRow]#</td>
  18.                 </cfloop>
  19.             </tr>
  20.         </cfloop>
  21.     </table>
  22. </cfoutput>

5 2913
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

That's just a list, so loop over it as you would a list.
Sep 19 '07 #2
Just in case you need an example of what acoder was saying:

Expand|Select|Wrap|Line Numbers
  1. <cfset session.sv = "Id,Name,Address,Phone,City,Location">
  2.  
  3. <cfquery name="qResults" datasource="#ds#" username="#un#" password="#pw#">
  4.     select #session.sv# from details
  5. </cfquery>
  6.  
  7. <cfoutput>
  8.     <table>
  9.         <tr>
  10.             <cfloop index="fieldname" list="#session.sv#">
  11.                 <th>#fieldname#</th>
  12.             </cfloop>
  13.         </tr>
  14.         <cfloop query="qResults">
  15.             <tr>
  16.                 <cfloop index="fieldname" list="#session.sv#">
  17.                     <td>qResults[fieldname][qResults.CurrentRow]#</td>
  18.                 </cfloop>
  19.             </tr>
  20.         </cfloop>
  21.     </table>
  22. </cfoutput>
Sep 21 '07 #3
acoder
16,027 Expert Mod 8TB
Thanks for the example. Makes it a lot easier to understand.
Sep 23 '07 #4
Thanks a bunch for responding with a code hint, it works great :-)
Sep 24 '07 #5
acoder
16,027 Expert Mod 8TB
Glad to hear you got it working. Post back anytime if you have more queries.
Sep 25 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: kaptain kernel | last post by:
i've got a while loop thats iterating through a text file and pumping the contents into a database. the file is quite large (over 150mb). the looping causes my CPU load to race up to 100 per...
1
by: Peter yeshew | last post by:
I have a query consiting of 2 columns : afid and SumOfLiters. The sql view of the query is the following: SELECT customers.afid, Sum(.liters) AS SumOfliters FROM (customers INNER JOIN orders ON...
3
by: Louis | last post by:
Is there a switch or a setting in Access so that a group by query doesn't return a field name SumOf(original field name)? Especially when you chain multiple queries together you'd get...
1
by: sinthreck | last post by:
have a query which gets data from two tables. There's about 20 fields worth of data. In VB code, I run this query: strPOItems = "SELECT * FROM LEFT JOIN OutstandingInvoices ON (.PartNumber =...
8
by: RC | last post by:
I have a table that lists many box numbers. Each box number has a Pallet Number (indicating which pallet the box is in). When the Pallets are loaded into a shipping Container I need to update the...
2
by: Delores | last post by:
I have been running make-table queries to create 10 tables (one for each unit) that are exported to Excel spreadsheets. Because of my limited knowledge with code, I've created 10 separate queries...
2
by: Venk | last post by:
hi all, I saw one reply to arun on the subject "Dynamic Query in Ms-Access" by one Mr Rick I found it very useful. Now to extend this solution forward I have the following situation. I...
6
by: Fuzzydave | last post by:
I am back developing futher our Python/CGI based web application run by a Postgres DB and as per usual I am having some issues. It Involves a lot of Legacy code. All the actual SQL Querys are...
10
by: Lloyd Harold | last post by:
I'm very new to PHP and attempting to put together a simple script for retrieving MySQL data of personal records. The MySQL table I'm using consists of: 0: id 1: name 2: location (an integer...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.