Author to Book TABLE

AUTHOR TO BOOK TABLE
Author ID Book ID
2 7
1 3
1 4
1 5
49 79
49 80
49 81
49 82
50 83
50 84
50 85
51 86
51 87
51 88
52 89
52 90
52 91
53 92
53 93
53 94
54 95
54 96
54 97
55 98
55 99
55 100
56 101
56 102
56 103
57 104
57 105
57 106
58 107
58 108
58 109
59 110
59 111
59 112
60 113
60 114
60 115
 

Note: Only the ID's of the Authors and ID's of the Books are in this table. This is a simple method to track the assignments of authors to books and vise-versa. This allows the Author and Book tables to be used by way of their specific ID's but does not require each table to show their relationships.

 

CODE FOLLOWS

<?php
    
//==================================================================
    //  author-book-table.php -- Show Author to Book Table
    //==================================================================

    // code
    
if (session_id() == '')
        {
        
session_start();
        }

    
session_name("sperlt");

    include(
'includes/functions.php');    // standard functions

    // init vars and arrays
    
$self basename($_SERVER['SCRIPT_NAME']);
    
$author_book_table 'author_book';

    
// author_book arrays
    
$authorID = array();
    
$bookID = array();

    
$con '';

    
//==================================================================
    // Pull in all author to book records
    //==================================================================

    
include('includes/open-db.php');

    
$query "SELECT * FROM $author_book_table ";
    
$comment "Could not get $author_book_table records: $query";
    
$result mysqli_query($con$query) or die(report($commentmysqli_error($con), __LINE____FILE__));

    while (
$row mysqli_fetch_array($result))
        {
        
$authorID[] = $row['author_id'];
        
$bookID[] = $row['book_id'];
        }

    include(
'includes/close-db.php');    //====== close dB
    
include('includes/header.php');

    
// Now show data
?>

    <h2 class="center">Author to Book TABLE</h2>

    <table class="full">
        <tr>
            <th colspan=4 class="header1">
                AUTHOR TO BOOK TABLE
            </th>
        </tr>
        <tr class="header2 center">
            <th>Author ID</th>
            <th>Book ID</th>
        </tr>

        <?php

            $i 
0;
            
// go through either of the author arrays (i.e., $author_first or $author_last)
            
foreach ($authorID as $key => $value)
                {
                
?>

                    <tr class="row<?php echo(++$i 1); ?>">
                        <td class="w30 center">
                            <?php echo($authorID[$key]); ?>
                        </td>
                        <td class="w30 center">
                            <?php echo($bookID[$key]); ?>
                        </td>
                    </tr>

                    <?php
                
}
        
?>

    </table>

    <div class="clear">
        &nbsp;
    </div>

    <p>
        Note: Only the ID's of the Authors and ID's of the Books are in this table. This is a simple method to track
        the assignments of authors to books and vise-versa. This allows the Author and Book tables to be used by way of
        their specific ID's but does not require each table to show their relationships.
    </p>

<?php
    
include('includes/footer.php');
?>