Foreach item in column


#1

Hi there,

I have a database with phonenumbers, and I want to make a function
that runs a command for each of these numbers, with the number as an
argument

Something like this in Perl:
system("/bin/command $number");

mysql> select * from numbers where list = “one”

±—±---------±---------±--------------------±----------+
| id | number | name | email | list |
±—±---------±---------±--------------------±----------+
| 2 | 9341 | Martin | removed_email_address@domain.invalid | one
±—±---------±---------±--------------------±----------+

It would be very helpful if anyone could give me some examples on how
to achieve this! :slight_smile:

I´ll be very grateful for all help I can get!

Best regards,
Martin S._______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


#2

| 2 | 9341 | Martin | removed_email_address@domain.invalid | one
±—±---------±---------±--------------------±----------+

Select the desired records in the controller. Then do a:

for person in @people
system(/bin/command person.number)
end

regards
Claus


#3

Hello,

On Mar 22, 2006, at 5:15 PM, Claus G. wrote:

| 2 | 9341 | Martin | removed_email_address@domain.invalid | one
±—±---------±---------±--------------------±----------+

Select the desired records in the controller. Then do a:

for person in @people
system(/bin/command person.number)
end

Thanks, Claus! But I didn´t quite get it to work

Here´s what I have done.

  • index.rhtml:
    <%= link_to ‘Iterate over all the numbers’, { :action =>
    ‘iterate’, }, %>

  • numbers_controller:

def iterate
@people = Number.find(:all,
:conditions => “list = ‘one’”)
for person in @people
system(“echo ‘person.number’ > /tmp/outout”)
end
end

$ cat /tmp/outout
person.number

How do I make it echo/print the variable, not just the name? I tried
with and without ’ around person.number.

Best regards,
Martin S._______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


#4

try this
system(“echo #{person.number} > /tmp/outout”)

Gokhan
www.sylow.net


#5

sorry, I though this is the whole posting!

:frowning:


#6

with_irony do
wow! i am deeply impressed…
end