Author to Book TABLE

AUTHOR TO BOOK TABLE
Author ID Book ID
17 3
17 12
17 26
17 32
25 23
25 24
25 25
25 26
2 7
1 3
1 4
1 5
30 33
30 34
24 18
12 12
31 35
31 36
31 37
32 38
32 39
36 46
36 47
36 48
37 49
37 50
37 51
38 35
38 37
38 43
20 3
39 52
39 53
39 54
40 55
40 56
40 57
41 58
41 59
41 60
42 61
42 62
42 63
43 64
43 65
43 66
44 67
44 68
44 69
45 70
45 71
45 72
46 73
46 74
46 75
47 76
47 77
47 78
 

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');
?>