SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2000
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    Database Example:
    ID | USER_ID | Description
    1 10000 car
    2 10000 computer
    3 10001 car
    4 10000 monitor



  2. #2
    SitePoint Addict
    Join Date
    Feb 2000
    Location
    District of Columbia
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Code:
    your_page.cfm
    Code:
    <cfquery datasource="table_space" name="query_name">
    select id,
           user_id,
           description
           from table_name
           where user_id = #passed_value#
    </cfquery>
    
    <cfparam name="start" default="1">
    
    <cfif IsDefined("start")>
       <cfset start_next = #start# + 1>
    </cfif>
    
    <table>
       <tr>
          <td>Description</td>
          <td>User_ID</td>
       </tr>
       <cfoutput query="query_name" startrow="#start#" maxrows="1">
       <tr>
          <td>#description#</td>
          <td>#user_id#</td>
       </tr>
       </cfoutput>
    </table>
    
    <cfoutput>
       <cfif #start_next# lte query_name.RecordCount><a href="your_page.cfm?start=#start_next#">Next</a></cfif>
    </cfoutput>

  3. #3
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    http://www.webmasterbase.com/article...d=228&pid=1039

    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>
    Select
    From
    Where
    LIMIT #number#, 1
    </CFQuery>

    <a href = "view.cfm?number=2">Next</a>

    You get the idea. Autoincrement the #number# variable each time and you're all set.

    Chris

  4. #4
    SitePoint Addict
    Join Date
    Feb 2000
    Location
    District of Columbia
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2000
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wonderfull !!! Thank You !!! I tried that code and it works perfect. Thank You again.

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2000
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How do I go back one record at a time.

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2000
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figureg it out. Just have the additions in the wrong place.
    Thank You again

  8. #8
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    Chris

  9. #9
    SitePoint Addict
    Join Date
    Feb 2000
    Location
    District of Columbia
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heh, chris
    i was about to test it myself!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •