Ruby Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesRuby Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 16th, 2006, 03:36 PM
CLEM_C_ROCK CLEM_C_ROCK is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 174 CLEM_C_ROCK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 27 m 11 sec
Reputation Power: 11
Help w/ pulling data from 2 tables and displaying the results

Hello,

I'm brand new to ruby and I'm having trouble pulling data from one
table (table_1), looping through the results and pulling data from
another table (table_2) and displaying the results of table_2 in one
field.

the pseudo code would be as follows:

Code:
result_1 = select first_name from table_1
loop results_1 
{
      puts "<tr><td> results_1.first_name<td>" 

      results_2 = select table_2.info from table_2 where table_1.user_id = table_2.user_id; 
        puts "<td>"
        loop results_2 
        { 
             puts "<li>table_2.info 
        } 
        puts "</td>" 
}


The display would look like this for 1 row:

joe | -info 1
-info 2
-info 3

Help - I'm desparate!
clem_c_rock is online now Report Post Edit/Delete Message

Last edited by CLEM_C_ROCK : December 17th, 2006 at 04:13 PM.

Reply With Quote
  #2  
Old December 17th, 2006, 02:39 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,406 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 10 h 20 m 32 sec
Reputation Power: 4080
Umm, you could revise your select statement to this:
Code:
select table1.first_name, table_2.info from table_2 where table_1.user_id = table_2.user_id;

This way, you need only one loop and the data is in the tabular format you need.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Reply With Quote
  #3  
Old December 19th, 2006, 12:59 PM
CLEM_C_ROCK CLEM_C_ROCK is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 174 CLEM_C_ROCK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 27 m 11 sec
Reputation Power: 11
Problem solved!

Ok - I finally buckled down and asked a couple of questions and there
was a method in the accounts model that was killing this whole concept:
Problem solved!

The project I'm building a little addition to is huge and extremely complex so there's a lot of code that could overide or clash w/ code I'm trying to develop.

That was the case here. In the Account model there was this method that was overiding my join attempts.

def spaces
spaces = Space.find :all, :conditions => ['owner_id = ?',
self.user_id]
end

Now, once I got rid of that method - this works perfectly!
@accounts = Account.find(:all, :include => :spaces, :limit => 20)

I got dumped right into the fire w/ this new project - it pays to ask a few simple questions. I tore a lot of hair out trying to figure it out, but also learned a great deal trying to find the answer.

posts!

Cheers!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesRuby Programming > Help w/ pulling data from 2 tables and displaying the results

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap