Ask a Question related to Coldfusion - Getting Started, Design and Development.
-
Bob Barrows #21
Re: array question
Hannibal wrote:
been there, done that> hehehe... i must apologise for that sad excuse of an answer...
>
What's wrong with using an array?> 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...
This is fine.>
> 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>"
Again: you're using an inefficient recordset loop, when you could be using a>
> '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) &
> " </TD>" Next
> Response.Write "</tr>"
> Rs.MoveNext
> Loop
>
> %>
> </table>
>
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-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... -
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,... -
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... -
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: ... -
[PHP] ARRAY QUESTION
Dale Hersh <mailto:dalehersh@hotmail.com> on Thursday, July 24, 2003 12:41 PM said: unset($myStuff); -
Chad Lupkes #22
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
-
OSIRIS #23
Re: array question
Chad Lupkes wrote:
Hello,> 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]
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];
}Try this...> include ("header.html");
> include ("title.html");
> if ( $govwebsite != "" ) { include ("countyweb.html"); };
> if ( $demwebsite != "" ) { include ("countydemweb.html"); };
> include("../navigation.html");
> include("../copyright.html");
> ?>
OSIRIS Guest
-
Chad Lupkes #24
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...experience in> Chad Lupkes wrote:> > I'm just starting in php, although I have a little programminghelp me.> > other languages, but only on a surface level. I'm hoping someone cana> >
> > I have a multidimensional array that I want to pull information from onarray> > 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 subsearched> > 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'vehave:> > and tried a bunch of things, and nothing is working. Here is what Ion line 12.> >
> > <?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.phpdoing wrong?> > Line 12 is the end of the foreach loop. Can someone tell me what I'm> Hello,> >
> > Chad Lupkes
> > [email]chadlupkes@earthlink.net[/email]
>
> 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
-
Sneelock #25
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
-
kglad webforumsuser@macromedia.com #26
Re:Array Question
enclose your loadMovie in another conditional to ensure the i<clipArray.length-1
kglad webforumsuser@macromedia.com Guest
-
Sneelock #27
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...i<clipArray.length-1> enclose your loadMovie in another conditional to ensure the>
>
Sneelock Guest
-
kglad webforumsuser@macromedia.com #28
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
-
Sneelock #29
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
-
webhead_1 #30
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
-
gumshoe #31
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
-
gumshoe #32
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



Reply With Quote

