SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I come with loops that can solve this problem of two (2) tables?

    Hello People,
    I have two tables(ref_A,ref_B). First table called ref_A has two fields. And the other table(ref_B) with 6 fields.
    Now, I want when first query runs it picks the first record in first table (ref_A) . then it goes to the second table (ref_B) and picks on the records that have a reference number as the firt record in first table (ref_A). The it goes to the second record in first table (ref_A) picks the second record and then goes to the second table and picks the records with same reference number. The tables are below. How can I do the loop in the PHP? Please help.

    ref_A
    Ref1 fields2
    1 Schools
    2 Hospitals



    ref_B

    fields1 Ref1 fields3 fields4 fields5 fields6
    1 2 rr tt hh no
    2 2 pp fg ho yes
    3 1 io oo bb no

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    In the query, you join the two tables on Ref1 and order by Ref1.
    Then, you loop through the result set (see example #2)

  3. #3
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do not want to use joins

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Joins are a big part of SQL; without them you are going to have inefficient, slower code which is harder on your server.

    Never be afraid to learn. If you've tried joins and they didn't work, just ask, that's what we're here for.

    But don't dismiss a KEY solution to many problems without a good reason.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •