Forum: Ruby Parsing data trouble

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
199b6c213f0ac380d3f794028bbbb286?d=identicon&s=25 unknown (Guest)
on 2007-01-19 16:30
(Received via mailing list)
Late in the day and I've hit a wall. Any help is appreciated.

Heres what I have:


<%
dbh =
DBI.connect("dbi:blank:dbname=products;host=blank;blank","blank","blank")

sth = dbh.execute("SELECT * FROM products")

while row = sth.fetch_array do
        puts "<br></br>"
        puts "Column Name : #{sth.column_names[0]}"
        puts "Column Name : #{sth.column_names[1]}"
        puts "Column Name : #{sth.column_names[2]}"
        puts "<br></br>"

%>


Now, as long as I use puts "Column Name : #{sth.column_names[0]}" and
increment column_names by hand I get my data.

EX.
Array_Grid_Header  =["Column Name : #{sth.column_names[0]}" ,
                                "Column Name : #{sth.column_names[1]}"
,
                                "Column Name : #{sth.column_names[2]}"
,
                                "Column Name : #{sth.column_names[3]}"
,
                                "Column Name : #{sth.column_names[4]}"
];

Problem is, I need this to be dynamic so I can insert it into my array.
I am a C++ programmer and cannot figure out how to do this in RUBY.

Also, this is embedded Ruby code into JavaScript

what I need is something like this:

         for(var nCount = 0; nCount < <%=sth.column_names.size%>;
nCount++)
         {
            Array_Grid_Header +=
["<%=sth.column_names[nCount].upcase%>"];

         }

This would give me the Array in need, but it doesn't like nCount.

See....<%=sth.column_names.size%> in my f'or loop' produces 15.
I need fill Array_Grid_Header with the column names .

Thank you in advance.
Fb7003990f4f0c6b3b31aa0183b683c0?d=identicon&s=25 Matt Gillooly (Guest)
on 2007-01-19 16:30
(Received via mailing list)
> what I need is something like this:
>
>          for(var nCount = 0; nCount < <%=sth.column_names.size%>;
> nCount++)
>          {
>             Array_Grid_Header +=
> ["<%=sth.column_names[nCount].upcase%>"];
>
>          }
>
try:
Array_Grid_Header += sth.column_names.collect{|c| c.upcase}
199b6c213f0ac380d3f794028bbbb286?d=identicon&s=25 unknown (Guest)
on 2007-01-19 16:57
(Received via mailing list)
Matt Gillooly wrote:
> try:
> Array_Grid_Header += sth.column_names.collect{|c| c.upcase}



Hey man. That was what I needed. I still don't have the data parsed
correctly yet but I did a
alert(Array_Grid_Header); and can now see how the data is sitting.

Kudos dude!
199b6c213f0ac380d3f794028bbbb286?d=identicon&s=25 unknown (Guest)
on 2007-09-25 22:33
(Received via mailing list)
Matt Gillooly wrote:
> try:
> Array_Grid_Header += sth.column_names.collect{|c| c.upcase}



Hey man. That was what I needed. I still don't have the data parsed
correctly yet but I did a
alert(Array_Grid_Header); and can now see how the data is sitting.

Kudos dude!
This topic is locked and can not be replied to.