php - limit input to a certain number for a sql table -
i have sql database within have series of different tables. basically, creating exam day , adding exams it.
example:
(examtable) exam 1
(exams) physics, biology, chemistry, p.e
these both linked.
now how works when create exam in examtable, can add unlimited amount of exams it, in real life not make sense.
so trying have sort of input when creating exam can limit amount of exams can entered it.
- so example if create exam 2 , limit input 3, 3 exams can added it.
i have tried find online cannot seem anywhere, please help?
thanks.
add column table called mostexams
when creating new exam just,
$db = new pdo('mysql:host=localhost;dbname=test', $user, $pass); $stmnt = $db->query("select `mostexams` `exams` `classid`='" . $thisclassid . "'"); while($row = $stmt->fetch(pdo::fetch_assoc)) { $mostexams = $row['mostexams'] ; } //php allow $mostexams number of exams. $stmnt = $db->query("select `id` `exams` `classid`='" . $thisclassid . "'"); if ($stmnt->rowcount() >= $mostexams){ echo 'you cannot add more exams. change mostexams in sql database allow more.'; }else{ //html form add exam }
you may want add code check , see if have exams , subtract exams. need think outside box little bit!
Comments
Post a Comment