I have two tables:
First table:
MEMBERS:
ID | FIRSTNAME | LASTNAME |
1 Jack Smith
2 Jane Baker
3 Peter Little
And the second table:
DETAILS:
SUBSCRIBER_ID | FIELD_ID | FIELD_VALUE |
1 1 Blue
1 2 Dogs
1 3 March
2 1 Pink
2 2 Cats
2 3 June
3 1 Black
3 2 Birds
3 3 September
The FIELD_ID represents other details over the member. i.e.
1 = Favorite color
2 = Favorite animal
3 = Favorite month
I want to pull a report that contains their main information MEMBERS & their extra information from the DETAILS table where the SUBSCRIBER_ID = the ID in Members. So for Jane it would look like:
- Jane
- Baker
- Pink
- Cats
- June
UPDATED:
I have used the following SQL statement and I pull the data I want, but the display is not as I am looking for:
SELECT members., details. from members INNER JOIN details ON members.id = details.subscriber_id WHERE jos_osmembership_subscribers.id = '29'
(WHERE purely reduce the record record to one member).
The result I am getting here is:
Jane | Baker | Pink
Jane | Baker | Cats
Jane | Baker | June
Whereas I am looking for
Jane | Baker | Pink | Cats | June
I'm using the following output which I know is 100% wrong :)
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "Results:" . $row["ID"] . "|";
echo "" . $row["FIRSTNAME"] . "|";
echo "" . $row["LASTNAME"] . "|";
echo "" . $row["field_value"] . "|";
}
Really I am looking for something that will let me output like:
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "Results:" . $row["ID"] . "|";
echo "" . $row["FIRSTNAME"] . "|";
echo "" . $row["LASTNAME"] . "|";
echo "" . $row["color"] . "|";
echo "" . $row["animal"] . "|";
echo "" . $row["month"] . "|";
}
Cheers