vendredi 9 mars 2018

Printing Entire mySQL Table on Condition [duplicate]

I am trying to print an entire mySQL table on the press of a button. There will be a list of buttons referencing each table, those will be added later, for now I'm trying to get the first to work and I am struggling.

I'm using a similar method elsewhere on my program and didn't have any issue with it. I'm fairly sure I'm not doing this the most efficient way either.

Current result is that the table generates, but the content is never filled. The "Test!" quote does print.

Note: I do not need them to press a button, it can print every table in the database on page load, but I didn't know how to do this.

<?php

if (isset($_GET['customer'])) {
    $query = "select * from customer;";

    $result = mysqli_query($link, $query ); 

    echo '<br>';
    echo '<table>';
    echo "<tr><th>Customer_Number</th><th>Surname</th><th>Initials</th><th>firstname</th><th>title</th><th>address1</th><th>address2</th><th>city</th><th>county</th><th>postcode</th><th>passwd</th><th>passphrase</th></tr>\n";

    while($row = mysqli_fetch_array( $result, MYSQLI_ASSOC ) ) 
    {
        echo "<tr>\n";
        echo 
            '<td>', $row[ 'customer_number' ], '</td>',
            '<td>', $row[ 'surname' ], '</td>',
            '<td>', $row[ 'initials' ], '</td>',
            '<td>', $row[ 'firstname' ], '</td>',
            '<td>', $row[ 'title' ], '</td>',
            '<td>', $row[ 'address1' ], '</td>',
            '<td>', $row[ 'address2' ], '</td>',
            '<td>', $row[ 'city' ], '</td>',
            '<td>', $row[ 'county' ], '</td>',
            '<td>', $row[ 'postcode' ], '</td>',
            '<td>', $row[ 'passwd' ], '</td>',
            '<td>', $row[ 'passphrase' ], '</td>', "\n";
        echo "</tr>\n";
    }
    echo '</table>';
    echo '<h1>Test!</h1>';
    mysqli_free_result( $result );
    mysqli_close( $link );
}

if (isset($_SESSION['manager'])) {
    echo '<form name="manager">';
    echo '<input type="submit"  value="Customer" name="customer">';
}
?>

I'm unsure of how well I've explained my problem, but hopefully the code explains where I'm going with this. Thanks.




Aucun commentaire:

Enregistrer un commentaire