SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    0 Post(s)
    0 Thread(s)

    Question How can I include an array in another array?

    This is for a congress website. I want to display the program. I have the following tables in a MySQL database:
    1. A table with the titles of the program events (events)
    2. A table with the different years (congress_year)
    - table 1 and 2 are connected by the column "congress_year_id" in table 1 that stores the year_id of the different years stored in table 2
    3. A table with the names of the persons involved as speakers or chairmen in the congress (persons)
    4. A lookup table that connects the events table with the persons table. This is important because some events are connected to more than one person and some persons are connected to more than one event

    Below is the code I use to SELECT the individual events and display them together with the persons that are involved in these events.
    The problem with the code is, that I get as many entries for the same event as there are persons connected to this event. How can I display only one line per event, but with all the persons involved?
    I guess I have to have an subarray for the persons in the main array $row, but I don't know how to do this.

    <table class="congressprogram">
    //get all events for day1 from events table
    // define the query
    $sql = "SELECT * FROM events ev, congress_year cy, eventcategory ec, persons pe, events2persons e2p
    WHERE cy.congress_year = '$chosenYear' AND cy.year_id = ev.congress_year_id AND event_day = '$databasedate1'
    AND ev.eventcategory_id = ec.category_id
    AND ev.event_id = e2p.event_id AND e2p.person_id = pe.person_id
    ORDER BY event_start, category_list_order";

    //perform a query getting back a MySQLResult object
    $result = $db->query($sql);

    //fetch rows from MsSQL one at a time
    while ($row = $result->fetch()) {
    $event_id = $row['event_id'];
    $event_day = $row['event_day'];
    $event_start = $row['event_start'];
    $event_end = $row['event_end'];
    $event_title_ge = htmlspecialchars($row['event_title_ge']);
    $event_title_fr = htmlspecialchars($row['event_title_fr']);
    $event_title_en = htmlspecialchars($row['event_title_en']);
    $event_location = htmlspecialchars($row['event_location']);
    $eventcategory_id = $row['eventcategory_id'];
    $congress_year_id = $row['congress_year_id'];

    $category_name = htmlspecialchars($row['category_name']);

    $firstname = htmlspecialchars($row['firstname']);
    $lastname = htmlspecialchars($row['lastname']);

    echo "<tr><td class=\"$category_name\">" . "$event_start" . "-" . "$event_end" . "</td><td class=\"$category_name\">" .
    "$event_title_ge" . " - " . "$event_title_fr" . "<br />"
    . "<span class=\"location\">$event_location</span>" . "<br />" . "$firstname" . " ". "$lastname". "</td></tr>";



  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Iowa, USA
    0 Post(s)
    0 Thread(s)
    Your question looks similar to the one from this thread.
    Jason Sweat ZCE -
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.


Posting Permissions

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