Problem with function ListGetAt

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Problem with function ListGetAt

    I have written the code for a DB driven image viewer. It is pretty simple. I
    am having a problem with my navagtion going to the previous and next links.
    The times when I have a problem is when I am on the number 2 in my list I don't
    see the previous link to get me to number 1. The other time when I see a
    problem is when I try to start on the number 1 in the list I get this error
    message.

    Error Occurred While Processing Request
    Invalid list index 0.
    In function ListGetAt(list, index [, delimiters]), the value of index, 0, is
    not a valid as the first argument (this list has 10 elements). Valid indexes
    are in the range 1 through the number of elements in the list.

    The Error Occurred in C:\CFusionMX\wwwroot\hunter\image_display.cfm: line 36

    34 : <cfset nextImageID = ListGetAt(ImageIDList, nextPos)>
    35 : <cfset prevPos = Listfind(ImageIDList, url.ID, ",") - 1>
    36 : <cfset prevImageID = ListGetAt(ImageIDList, prevPos)>
    37 :
    38 : <table width="100%" border="0" cellpadding="0" cellspacing="0"
    bgcolor="#9999CC">


    Can someone please help.



    <!--- Get All Pictures --->
    <cfquery name="qGetPictures" datasource="hmddb">
    SELECT *
    FROM Test
    </cfquery>

    <!--- Query the original query to grab 1 Picture --->
    <cfquery name="qGetSinglePic" dbtype="query">
    SELECT *
    FROM qGetPictures
    WHERE ID = #URL.ID#
    </cfquery>

    <!--- mechanism to grab Image IDS --->
    <cfset ImageIDList="">
    <!--- Make List of the Picture IDs --->
    <cfloop query="qGetPictures">
    <cfset ImageIDList=#ListAppend(ImageIDList, qGetPictures.ID)#>
    </cfloop>

    <!--- Get the Locations of the ID in the List --->
    <!--- Set the IDs for the next and prev buttons --->
    <cfset nextPos = Listfind(ImageIDList, url.ID, ",") + 1>
    <cfset nextImageID = ListGetAt(ImageIDList, nextPos)>
    <cfset prevPos = Listfind(ImageIDList, url.ID, ",") - 1>
    <cfset prevImageID = ListGetAt(ImageIDList, prevPos)>

    <table width="100%" border="0" cellpadding="0" cellspacing="0"
    bgcolor="#9999CC">
    <tr>
    <cfoutput query="qGetSinglePic">
    <td align="center"><img src=Portfolio/images/5/#imageName#></td>
    </cfoutput>
    </tr>
    <tr>
    <td align="center"><cfoutput><cfif ListFirst(ImageIDList , ",") NEQ
    prevImageID> <a href="image_display.cfm?ID=#prevImageID#">Prev image</a></cfif>
    | <cfif ListLast(ImageIDList , ",") NEQ nextImageID><a
    href="image_display.cfm?ID=#nextImageID#">Next image</a></cfif></cfoutput></td>
    </tr>

    </table>

    murpg Guest

  2. Similar Questions and Discussions

    1. ListGetAt in CFQUERY
      I have a database of computer components that helps drive a custom system builder. I have 1 price field that has a list of prices delimited with an...
    2. Problem using GD function
      Hi all, I've got a Red Hat 9 system with gd-1.8.4 installed and php-4.3.4 working on apache 2.0.48. When I try to use the imagecreatefromjpeg...
    3. problem with db function php
      hi echo '<table>'; $requete = mysql_query("SELECT liv_nolivre, sec_nosection, liv_commentaire, liv_titre FROM livre"); if (...
    4. Function Problem
      Hi, I have the following function below used to make a couple of calculations however as soon as I have two records the function calculation is...
    5. [PHP] problem with imagettfbbox() function
      I installed PHP 4.3.3 with default values. When I moved my sites, who use imagettfbbox() function, I received message -Fatal error: Call to...
  3. #2

    Default Re: Problem with function ListGetAt

    The following is certain to cause errors at some point:
    <cfset prevPos = Listfind(ImageIDList, url.ID, ",") - 1>
    because when the listfind() returns 1 then prevPos will be 0, and
    as you can see it causes an error when you use ListGetAt() with a zero
    position.



    OldCFer Guest

  4. #3

    Default Re: Problem with function ListGetAt

    I understand what's causing this, but how do I fix it? I can't think the logic all the way through.
    murpg Guest

  5. #4

    Default Re: Problem with function ListGetAt

    Without writing the code for you, here's how to fix it:

    You need to add <cfif> logic...
    Page 1 does not have a "previous" link and the last page does not have a
    "next" link.

    Such logic would eliminate the listindex problems you are seeing.

    -- MikeR

    MikerRoo Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139