Jump to content

[SOLVED] Help needed with mysql query and arrays


giraffemedia

Recommended Posts

Hi

 

I've got a mysql query using three joined tables and I can get the data from two of them fine, but I have a problem with the third one. table3 contains lot's of rows that have a foreign key that corresponds with the primary key from table2.

 

There are multiple entries for each table2 primary key in table3 and I would like to use the data as one long comma separated string of text as it contains issue numbers I would like the user to be able to see.

 

How can I get this information as an array whilst still getting table1 and table2 as normal? I have drawn some table below to show what I am trying to achieve...

 

 

table1 - contacts

contacts_id

     

contact_name

1

     

Homer

2

     

Marge

3

     

Maggie

4

     

Bart

5

     

Lisa

6

     

Barney

7

     

Ned

 

table2 - bookings

bf_id

     

bf_contacts_id

1

     

2

2

     

2

3

     

1

4

     

3

5

     

2

6

     

3

7

     

4

 

table3 - issues_booked

issue_id

     

issue_number

     

bf_id_number

1

     

60

     

2

2

     

61

     

2

3

     

62

     

2

4

     

58

     

1

5

     

59

     

1

6

     

60

     

1

7

     

61

     

1

8

     

62

     

1

9

     

45

     

3

10

     

46

     

3

11

     

47

     

3

12

     

48

     

3

13

     

49

     

3

14

     

50

     

3

15

     

70

     

4

16

     

71

     

4

17

     

72

     

4

 

I'd like it to look like the following...

 

Homer 45, 46, 47, 48 49, 50

Marge 60, 61, 62

 

etc etc

 

Can anyone help?

 

Regards

 

James

Link to comment
Share on other sites

It's alive.....it's alive!!

 

I've managed to get it working by using a query to make an array for the issues booked and changing my main query to:

 

$get_booking_query = "SELECT DISTINCT bf_id, bf_company_id, section, contactonefirstname, pre_payment FROM booking_form AS b LEFT JOIN contacts AS c ON b.bf_company_id = c.contacts_id LEFT JOIN issues_booked AS i ON i.ib_booking_form_number = b.bf_id WHERE bf_id IN('".implode("', '", $issues)."') ORDER BY bf_id";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.