Sunday, 15 February 2015

php - how to generate a row for every date inserted and add a attending slot for every member added -



php - how to generate a row for every date inserted and add a attending slot for every member added -

i have easy table

http://gyazo.com/4ef60f33b16b43884ab64d9db23f18e3

this simple mysqli html table

basically im struggling adding rows/columns every date added

i have 2 dates

gyazo.com/f6d7020842e1cbafa75f9295340ad49b

i have attendance table

gyazo.com/f88659eef625a14ee41fbe1f4ed30ab2

attending = 1 meaning person @ event

http://gyazo.com/c4bc3fdbc85c642bf45ec173019b7b60

i want , every fellow member added generate same columns , rows dates

current code

<!doctype html public "-//w3c//dtd html 4.01//en" "http://www.w3.org/tr/html4/strict.dtd"> <html> <head> <title>attendance system</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body> <h1>attendance system</h1> <?php // connect database include('connect-db.php'); // records database if ($result = $mysqli->query("select * players order case when rank = 'colonel' 0 when rank = 'lieutenant-colonel' 1 when rank = 'major' 2 when rank = 'captain' 3 when rank = 'lieutenant' 4 when rank = 'ensign' 5 when rank = 'serjeant major' 6 when rank = 'colour serjeant' 7 when rank = 'serjeant' 8 when rank = 'corporal' 9 when rank = 'lance corporal' 10 when rank = 'private' 11 when rank = 'recruit' 12 end, rank")) { // display records if there records display if ($result->num_rows > 0) { // display records in table echo "<table border='1' cellpadding='10'>"; // set table headers echo "<tr><th>id</th><th>alias</th><th>historical name</th><th>rank</th><th>company</th><th>attending</th>"; echo "</tr>"; // close table headers while ($row = $result->fetch_object()) { // set row each record echo "<tr>"; echo "<td>" . $row->id . "</td>"; echo "<td>" . $row->firstname . "</td>"; echo "<td>" . $row->lastname . "</td>"; echo "<td>" . $row->rank . "</td>"; echo "<td>" . $row->company . "</td>"; echo "<td> attending </td>"; echo "</tr>"; } echo "</table>"; } // if there no records in database, display alert message else { echo "no results display!"; } } // show error if there issue database query else { echo "error: " . $mysqli->error; } // close database connection $mysqli->close(); ?> </body> </html>

did seek utilize n:m relation between attendance , date table?

this solve problem in best way guess. should create table attendance_has_eventdate (in case tables named way) table has 1:n relation both of tables.

i recommend mysql workbench. tool can design db quite , it's free.

php html mysqli

No comments:

Post a Comment