Hi guys,

wondered if someone could help please, i am trying to display a championship table from the 3 tables i have in my mysql.

tbl_champ holds the championship name (nitro) and date (2015)
tbl_rounds holds the round name (round1 so on) the date (01/01/2015 so on) and the champ_id
tbl_position holds the round_id, positions (1, 2, 3 etc) and racer_id (2, 4, 8 etc)

inserting and updating the tables work great,

but i cannot seem to get them to display as i want

this is what i have

            $sql_get_champ = mysql_query("SELECT * FROM `championship`") or die(mysql_error());
            while ($row_get_champ = mysql_fetch_array($sql_get_champ)) {
                echo '<div class="carwidget1">';
                    echo '<h3>' . $row_get_champ[1] . ' Championship ' . $row_get_champ[2] . '</h3>';
                    echo '<table id="pages">';
                        echo '<thead>';
                            echo '<th colspan="2"></th>';
                            $champ_id = $row_get_champ[0];
                            $sql_get_round_name = mysql_query("SELECT `round_name` FROM `rounds` WHERE `round_champ_id`='$champ_id'") or die(mysql_error());
                            while ($row_get_round_name = mysql_fetch_array($sql_get_round_name)) {
                                echo '<th style="font-size:14px;">' . $row_get_round_name[0] . '</th>';
                            } 
                            echo '<th colspan="2"></th>';
                        echo '</thead>';
                        echo '<thead>';
                            echo '<th>Position</th>';
                            echo '<th>Driver</th>';
                            $sql_get_round_date = mysql_query("SELECT `round_date` FROM `rounds` WHERE `round_champ_id`='$champ_id'") or die(mysql_error());
                            while ($row_get_round_date = mysql_fetch_array($sql_get_round_date)) {
                                $date = $row_get_round_date[0];
                                $dates = explode("-", $date);
                                $monthNum  = $dates[1];
                                $dateObj   = DateTime::createFromFormat('!m', $monthNum);
                                $monthName = $dateObj->format('F');
                                $mName = substr($monthName, 0, 3);
                                echo '<th style="font-size:12px;">' . $dates[2] . ' ' . $mName . '</th>';
                            }
                            $count = (mysql_num_rows($sql_get_round_date) / 2) + 1;
                            echo '<th>Best '.$count.'</th>';
                            echo '<th>Overall</th>';
                        echo '</thead>';

                        $sql_get_round_info = mysql_query("SELECT `rounds_id` FROM `rounds` WHERE `round_champ_id`='$champ_id'") or die(mysql_error());
                        while ($row_get_round_info = mysql_fetch_array($sql_get_round_info)) {
                            $round_id = $row_get_round_info[0];
                            $sql_get_finals_info = mysql_query("SELECT * FROM `positions` WHERE `pos_round_id`='$round_id'") or die(mysql_error());
                        echo '<tr>';
                        echo '<td></td>';
                            while ($row_get_finals_info = mysql_fetch_array($sql_get_finals_info)) {
                                echo '<td>'.$row_get_finals_info[3].'</td>';
                            }
                        echo '</tr>';
                        }
                    echo '</table>';
                echo '</div>';
            }

i get the headers the way i want but the racer ids are being display horizontally not vertically linked to the rounds
what im aiming for is here: Click Here (i've built the table in excel)

any ideas? am i just thinking about this all wrong

Hi,

you can set only one thead for each table, here you're setting two of them, and the number of columns must match those in the tbody block. You can set multiple tbody blocks, for example you can create a tbody block to emulate the second header. Otherwise you have to create two separated tables.

Really basic code looks like:

<table>

    <thead>
        <th></th>
        <th></th>
        <th></th>

    <!-- sub header -->
    <tbody>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>

    <!-- data here -->
    <tbody>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>

    <tfoot>
        <tr>
            <td></td>
            <td></td>
            <td></td>
        </tr>

</table>        

Here's an example with two tbody blocks and arrays as dataset:

Just click Run to see the execution of the code. You can edit it, just be aware that in the next few hours (8pm PST) Runnable is going in maintainance mode, so any eventual draft you create will be deleted.

Besides your link is broken, is missing the .com.

ah yes, i was over thinking it, thank you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.