Ask a Question related to Coldfusion - Getting Started, Design and Development.

  1. #21

    Default Re: array question

    Hannibal wrote:
    > hehehe... i must apologise for that sad excuse of an answer...
    >
    been there, done that
    > i was not looking at the bigger picture, merely fixing ths code i saw
    > in front of me...
    >
    > there's a much easier way to display the data WITHOUT creating array's
    > etc...
    What's wrong with using an array?
    >
    > actually i use it as part of a web based sql management system of
    > mine... <table blah blah>
    > <%
    > 'do the headings/column names
    > Response.Write "<tr>"
    > For Each Item in Rs.Fields
    > Response.Write "<th>" & Item.Name & "</th>"
    > Next
    > Response.Write "</tr>"
    This is fine.
    >
    > 'then do the rows of data
    > Do while (Not Rs.eof)
    > Response.Write "<tr>"
    > For Index=0 to (Rs.fields.count-1)
    > Response.Write "<TD VAlign=top>" & Rs(Index) &
    > "&nbsp;</TD>" Next
    > Response.Write "</tr>"
    > Rs.MoveNext
    > Loop
    >
    > %>
    > </table>
    >
    Again: you're using an inefficient recordset loop, when you could be using a
    blindingly fast array loop. Try this instead:

    If not Rs.eof then arResults = Rs.GetRows
    Rs.close
    set Rs=nothing
    'close and destroy your connection

    If IsArray(arResults) then
    For iRow = 0 to ubound(arResults,2)
    response.write "<tr>"
    For iCol = 0 to ubound(arResults,1)
    response.write "<td VAlign=top>"
    response.write arResults(iCol, iRow)
    response.write "</td>"
    next
    response.write "</tr>"
    Next
    else
    response.write "<tr><td colspan=" & ubound(arResults,1) + 1
    response.write " align = "center">No records were returned</td></tr>
    end if

    HTH,
    Bob Barrows


    Bob Barrows Guest

  2. Similar Questions and Discussions

    1. 2-Dimensional Array Question
      This is my first time using an array. 1. My code seems to work but I need to return a count from each piece of the array (the number of each...
    2. array question help
      i am new to arrays and have practiced some tutorials for instance aligning information in rows and columns then categorizing them numerically,...
    3. simple array question?
      On 12-Aug-2003, "Randell D." <you.can.email.me.at.randelld@yahoo.com> wrote: http://www.php.net/manual/en/function.list.php -- Tom...
    4. array question (grep -v on array)
      Hi, I have an output of errors fed into an array, after which I only look at things I care about and put them in a different array: ...
    5. [PHP] ARRAY QUESTION
      Dale Hersh <mailto:dalehersh@hotmail.com> on Thursday, July 24, 2003 12:41 PM said: unset($myStuff);
  3. #22

    Default array question

    I'm just starting in php, although I have a little programming experience in
    other languages, but only on a surface level. I'm hoping someone can help me.

    I have a multidimensional array that I want to pull information from on a
    bunch of pages.

    $county = array (
    array (
    key=>"adams",
    name=>"Adams",
    govwebsite=>"http://www.co.adams.wa.us/default.asp"
    demwebsite=>"" ),
    array ( name=>"Asotin",

    I'm trying to write the php script for the pages to identify the sub array
    by the filename, pull the rest of the information out of the array into
    variables, and then use those variables to write the page. I've searched
    and tried a bunch of things, and nothing is working. Here is what I have:

    <?php
    include("countiesarray.inc");
    $path = __FILE__;
    $filename = basename ($path,".php");
    foreach ($county as $key => $ArrayRow)
    {
    if ($ArrayRow[0] == $filename)
    {$countyname = $ArrayRow[name];
    $govwebsite = $ArrayRow[govwebsite];
    $demwebsite = $ArrayRow[demwebsite];
    };
    );
    include ("header.html");
    include ("title.html");
    if ( $govwebsite != "" ) { include ("countyweb.html"); };
    if ( $demwebsite != "" ) { include ("countydemweb.html"); };
    include("../navigation.html");
    include("../copyright.html");
    ?>

    The error I get is Parse error:
    parse error in /home/calador/public_html/wapolitics/counties/adams.php on line 12.
    Line 12 is the end of the foreach loop. Can someone tell me what I'm doing wrong?

    Chad Lupkes
    [email]chadlupkes@earthlink.net[/email]
    Chad Lupkes Guest

  4. #23

    Default Re: array question

    Chad Lupkes wrote:
    > I'm just starting in php, although I have a little programming experience in
    > other languages, but only on a surface level. I'm hoping someone can help me.
    >
    > I have a multidimensional array that I want to pull information from on a
    > bunch of pages.
    >
    > $county = array (
    > array (
    > key=>"adams",
    > name=>"Adams",
    > govwebsite=>"http://www.co.adams.wa.us/default.asp"
    > demwebsite=>"" ),
    > array ( name=>"Asotin",
    >
    > I'm trying to write the php script for the pages to identify the sub array
    > by the filename, pull the rest of the information out of the array into
    > variables, and then use those variables to write the page. I've searched
    > and tried a bunch of things, and nothing is working. Here is what I have:
    >
    > <?php
    > include("countiesarray.inc");
    > $path = __FILE__;
    > $filename = basename ($path,".php");
    > foreach ($county as $key => $ArrayRow)
    > {
    > if ($ArrayRow[0] == $filename)
    > {$countyname = $ArrayRow[name];
    > $govwebsite = $ArrayRow[govwebsite];
    > $demwebsite = $ArrayRow[demwebsite];
    > };
    > );
    > include ("header.html");
    > include ("title.html");
    > if ( $govwebsite != "" ) { include ("countyweb.html"); };
    > if ( $demwebsite != "" ) { include ("countydemweb.html"); };
    > include("../navigation.html");
    > include("../copyright.html");
    > ?>
    >
    > The error I get is Parse error:
    > parse error in /home/calador/public_html/wapolitics/counties/adams.php on line 12.
    > Line 12 is the end of the foreach loop. Can someone tell me what I'm doing wrong?
    >
    > Chad Lupkes
    > [email]chadlupkes@earthlink.net[/email]
    Hello,

    There is a little error in your code. This following script should be ok:
    > <?php
    > include("countiesarray.inc");
    > $path = __FILE__;
    > $filename = basename ($path,".php");
    > foreach ($county as $key => $ArrayRow)
    > {
    > if ($ArrayRow[0] == $filename)
    > {$countyname = $ArrayRow[name];
    > $govwebsite = $ArrayRow[govwebsite];
    > $demwebsite = $ArrayRow[demwebsite];
    }
    }
    > include ("header.html");
    > include ("title.html");
    > if ( $govwebsite != "" ) { include ("countyweb.html"); };
    > if ( $demwebsite != "" ) { include ("countydemweb.html"); };
    > include("../navigation.html");
    > include("../copyright.html");
    > ?>
    Try this...

    OSIRIS Guest

  5. #24

    Default Re: array question

    Ok, we're getting closer, but I'm still getting errors.

    Parse error: parse error, expecting `')'' in
    /home/calador/public_html/wapolitics/counties/countiesarray.inc on line 7

    Warning: Invalid argument supplied for foreach() in
    /home/calador/public_html/wapolitics/counties/adams.php on line 5

    --
    Chad Lupkes
    [email]chadlupkes@yahoo.com[/email]
    [url]http://www.seattlewebcrafters.com/[/url]
    "OSIRIS" <djtechno@free.fr> wrote in message
    news:3fc06f24$0$2804$626a54ce@news.free.fr...
    > Chad Lupkes wrote:
    > > I'm just starting in php, although I have a little programming
    experience in
    > > other languages, but only on a surface level. I'm hoping someone can
    help me.
    > >
    > > I have a multidimensional array that I want to pull information from on
    a
    > > bunch of pages.
    > >
    > > $county = array (
    > > array (
    > > key=>"adams",
    > > name=>"Adams",
    > > govwebsite=>"http://www.co.adams.wa.us/default.asp"
    > > demwebsite=>"" ),
    > > array ( name=>"Asotin",
    > >
    > > I'm trying to write the php script for the pages to identify the sub
    array
    > > by the filename, pull the rest of the information out of the array into
    > > variables, and then use those variables to write the page. I've
    searched
    > > and tried a bunch of things, and nothing is working. Here is what I
    have:
    > >
    > > <?php
    > > include("countiesarray.inc");
    > > $path = __FILE__;
    > > $filename = basename ($path,".php");
    > > foreach ($county as $key => $ArrayRow)
    > > {
    > > if ($ArrayRow[0] == $filename)
    > > {$countyname = $ArrayRow[name];
    > > $govwebsite = $ArrayRow[govwebsite];
    > > $demwebsite = $ArrayRow[demwebsite];
    > > };
    > > );
    > > include ("header.html");
    > > include ("title.html");
    > > if ( $govwebsite != "" ) { include ("countyweb.html"); };
    > > if ( $demwebsite != "" ) { include ("countydemweb.html"); };
    > > include("../navigation.html");
    > > include("../copyright.html");
    > > ?>
    > >
    > > The error I get is Parse error:
    > > parse error in /home/calador/public_html/wapolitics/counties/adams.php
    on line 12.
    > > Line 12 is the end of the foreach loop. Can someone tell me what I'm
    doing wrong?
    > >
    > > Chad Lupkes
    > > [email]chadlupkes@earthlink.net[/email]
    > Hello,
    >
    > There is a little error in your code. This following script should be ok:
    > > <?php
    > > include("countiesarray.inc");
    > > $path = __FILE__;
    > > $filename = basename ($path,".php");
    > > foreach ($county as $key => $ArrayRow)
    > > {
    > > if ($ArrayRow[0] == $filename)
    > > {$countyname = $ArrayRow[name];
    > > $govwebsite = $ArrayRow[govwebsite];
    > > $demwebsite = $ArrayRow[demwebsite];
    > }
    > }
    > > include ("header.html");
    > > include ("title.html");
    > > if ( $govwebsite != "" ) { include ("countyweb.html"); };
    > > if ( $demwebsite != "" ) { include ("countydemweb.html"); };
    > > include("../navigation.html");
    > > include("../copyright.html");
    > > ?>
    >
    > Try this...
    >

    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    Version: 6.0.543 / Virus Database: 337 - Release Date: 11/22/2003


    Chad Lupkes Guest

  6. #25

    Default Array Question

    Hi all,
    how does one stop this function from attempting to load an array element
    past it's length, (+ & -)?
    Or, where do I check in the code stack?
    Thanks for your time,
    Jon
    //
    next_btn.onRelease = function() {
    for (var i = 0; i<clipArray.length; i++) {
    if (clipArray[i] == here) {
    // The +1 yields "undefined" when the length is reached
    // I just want it to stop, or go back to [0] when the last
    // element is loaded
    loadMovie(clipArray[i+1], loader_mc);
    }
    }
    };



    Sneelock Guest

  7. #26

    Default Re:Array Question

    enclose your loadMovie in another conditional to ensure the i<clipArray.length-1


    kglad webforumsuser@macromedia.com Guest

  8. #27

    Default Re: Re:Array Question

    Thanks for the look k,
    I'm attempting just what you suggested
    I'm just getting tangled up in the condition.
    I thought I could create a var from the loaded clips to compare with the
    ..length of my array...
    but I don't quite have it working....yet.
    If you know of a better way, let me know, if you don't mind.
    Thanks again,
    Jon

    "kglad" <webforumsuser@macromedia.com> wrote in message
    news:bu7iq5$djc$1@forums.macromedia.com...
    > enclose your loadMovie in another conditional to ensure the
    i<clipArray.length-1
    >
    >

    Sneelock Guest

  9. #28

    Default Re: Re:Array Question

    well, i'm not sure what you're trying to with your "here" variable, but to avoid the problem mentioned in your thread you can use this code:
    next_btn.onRelease = function() {
    for (var i = 0; i<clipArray.length; i++) {
    if (clipArray == here) {
    // The +1 yields "undefined" when the length is reached
    // I just want it to stop, or go back to [0] when the last
    // element is loaded
    if(i<clipArray.length-1){
    loadMovie(clipArray[i+1], loader_mc);
    }
    }
    }
    };


    kglad webforumsuser@macromedia.com Guest

  10. #29

    Default Re: Re:Array Question

    Yah, cool, thanks.
    Right now I'm setting a number var to compare with the [i]
    So I get a true loop around the array.
    downside is I need to set this var from the loaded clip, not very opp.
    I'll try out your bit of code, looks nice and neat.
    I'm not sure what I'm doing with the "here" var, it does something, maybe I
    just like knowing where I am :)
    Thanks again!
    Jon


    Sneelock Guest

  11. #30

    Default Array question

    Take for instance you have the following array. How would I go about combining
    the elements of the array that match and get a total of the matching elements?
    I have been pounding my head against this problem for 2 days. :disgust; <----
    Array ----> <cfset counter = arraynew(2)> <cfset counter[1][1] = 'ICO5-07'>
    <cfset counter[1][2] = '10/11/05'> <cfset counter[1][3] = '597'> <cfset
    counter[2][1] = 'ICO5-07'> <cfset counter[2][2] = '10/11/05'> <cfset
    counter[2][3] = '597'> <cfset counter[3][1] = 'ICO5-08'> this element has a
    different ID <cfset counter[3][2] = '10/11/05'> <cfset counter[3][3] = '597'>
    <cfset counter[4][1] = 'ICO5-07'> <cfset counter[4][2] = '10/11/05'> <cfset
    counter[4][3] = '597'> <---- Array ----> <--- Array output ---> <cfloop
    from='1' to='#arraylen(counter)#' index='x'> <cfoutput> #x#
    #counter[x][1]#<br> </cfoutput> </cfloop> <--- Array output ---> <--- result
    of output ----> 1 ICO5-07 2 ICO5-07 3 ICO5-08 4 ICO5-07 <--- result of output
    ----> <--- output needed ---> 3 ICO5-07 1 ICO5-08 <--- output needed --->

    webhead_1 Guest

  12. #31

    Default Re: Array question

    A little ambiguous, but anyway:

    why not just do what you did, but instead of doing the cfoutput when you do,
    add these values to a new array or list . Except before you add them to this
    new list , do a quick check with, say, listFind(), to see if it was already
    added in a previous iteration. When done, you should be left with only the
    distinct values.

    Once you have isolated the complete 'doubled-up values' version of the array
    in a new array (or list) it will be realtively easy to loop through again
    and grab only unique values. In fact, a place like [url]www.cflib.org[/url] probarbly
    already has a 'getUniqueValuesOnly()' style function, you could check it
    out.

    Its hard to read your code as it has come through all on a single line in my
    newsreader, so apolgies if I have misunderstood.



    "webhead_1" <webforumsuser@macromedia.com> wrote in message
    news:cvo6ib$qg5$1@forums.macromedia.com...
    > Take for instance you have the following array. How would I go about
    > combining
    > the elements of the array that match and get a total of the matching
    > elements?
    > I have been pounding my head against this problem for 2 days. :disgust;
    > <----
    > Array ----> <cfset counter = arraynew(2)> <cfset counter[1][1] =
    > 'ICO5-07'>
    > <cfset counter[1][2] = '10/11/05'> <cfset counter[1][3] = '597'> <cfset
    > counter[2][1] = 'ICO5-07'> <cfset counter[2][2] = '10/11/05'> <cfset
    > counter[2][3] = '597'> <cfset counter[3][1] = 'ICO5-08'> this element has
    > a
    > different ID <cfset counter[3][2] = '10/11/05'> <cfset counter[3][3] =
    > '597'>
    > <cfset counter[4][1] = 'ICO5-07'> <cfset counter[4][2] = '10/11/05'>
    > <cfset
    > counter[4][3] = '597'> <---- Array ----> <--- Array output ---> <cfloop
    > from='1' to='#arraylen(counter)#' index='x'> <cfoutput> #x#
    > #counter[x][1]#<br> </cfoutput> </cfloop> <--- Array output ---> <---
    > result
    > of output ----> 1 ICO5-07 2 ICO5-07 3 ICO5-08 4 ICO5-07 <--- result of
    > output
    > ----> <--- output needed ---> 3 ICO5-07 1 ICO5-08 <--- output needed --->
    >

    gumshoe Guest

  13. #32

    Default Re: Array question

    Here you go, CFLib.org does has such a function, just checked:

    [url]http://www.cflib.org/udf.cfm?id=1193[/url]


    I think this may what you are looking for, right?

    "webhead_1" <webforumsuser@macromedia.com> wrote in message
    news:cvo6ib$qg5$1@forums.macromedia.com...
    > Take for instance you have the following array. How would I go about
    > combining
    > the elements of the array that match and get a total of the matching
    > elements?
    > I have been pounding my head against this problem for 2 days. :disgust;
    > <----
    > Array ----> <cfset counter = arraynew(2)> <cfset counter[1][1] =
    > 'ICO5-07'>
    > <cfset counter[1][2] = '10/11/05'> <cfset counter[1][3] = '597'> <cfset
    > counter[2][1] = 'ICO5-07'> <cfset counter[2][2] = '10/11/05'> <cfset
    > counter[2][3] = '597'> <cfset counter[3][1] = 'ICO5-08'> this element has
    > a
    > different ID <cfset counter[3][2] = '10/11/05'> <cfset counter[3][3] =
    > '597'>
    > <cfset counter[4][1] = 'ICO5-07'> <cfset counter[4][2] = '10/11/05'>
    > <cfset
    > counter[4][3] = '597'> <---- Array ----> <--- Array output ---> <cfloop
    > from='1' to='#arraylen(counter)#' index='x'> <cfoutput> #x#
    > #counter[x][1]#<br> </cfoutput> </cfloop> <--- Array output ---> <---
    > result
    > of output ----> 1 ICO5-07 2 ICO5-07 3 ICO5-08 4 ICO5-07 <--- result of
    > output
    > ----> <--- output needed ---> 3 ICO5-07 1 ICO5-08 <--- output needed --->
    >

    gumshoe 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