Here is what I would like to do. I would like to use something like the wizard record view. However the table is a complete equipment table with many many records. This table has a primary key column "ID"(Autonumbered) it also has a column that has what "user id" has that piece of equipment. I know how to pass the user id and display the first piece of equipment that the user has. What code to I need to be able to click the "next" button and view the next piece of equipment that user has... Not just the next Record.
If anyone has any suggestions I will be greatfull.
ID | USER_ID | Description
1 10000 car
2 10000 computer
3 10001 car
4 10000 monitor
I haven't tested this code, but it should work. The idea is that you have a query which returns multiple rows. You output them one by one. Thats it.
<cfquery datasource="table_space" name="query_name">
where user_id = #passed_value#
<cfparam name="start" default="1">
<cfset start_next = #start# + 1>
<cfoutput query="query_name" startrow="#start#" maxrows="1">
<cfif #start_next# lte query_name.RecordCount><a href="your_page.cfm?start=#start_next#">Next</a></cfif>
umm. Just use limits.
A limit is a function in SQL, not specifically to do with Cold Fusion.
While Temis' example is nice I don't think what it is you are looking for. And is definitely more complicated than using a simple limit.
Since its just an SQL issue you can learn about limits from Kevin's PHP/MySQL Tutorial.
Go there and just ignore the PHP code and pay attention to the SQL.
Basically a limit will just return the rows you want. It goes after the rest of your SQL and can be used a few ways.
Limit # will just return the amount of rows specified in #
Limit A, B will return the amount of rows(B) starting from row A.
So for you you'd do something like this:
<CFQUERY blah blah>
LIMIT #number#, 1
<a href = "view.cfm?number=2">Next</a>
You get the idea. Autoincrement the #number# variable each time and you're all set.
Thats a nice trick. I didnt know it, thanks Chris. :)
In this one you have to hit the DB every time you want to see another record, as opposed to hitting it just once... That could slow down the site, depending on the size of your database.
Wonderfull !!! Thank You !!! I tried that code and it works perfect. Thank You again.
How do I go back one record at a time.
I figureg it out. Just have the additions in the wrong place.
Thank You again
hrm apparently I was wrong. I just always assumed that a limit would work in CF since it is part of SQL. But apparently it does not, as I was just finishing up my article I tested it to be sure since I had never tried it before, and nope. I guess I shouldn't assume things without testing them.
heh, chris :)
i was about to test it myself!