PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $studentsList = array('Иван', 'Николай', 'Михаил', 'Владимир', 'Петр', 'Лидия', 'Анфиса', 'Артур', 'Сергей', 'Таня', 'Света', 'Григорий', 'Афанасий', 'Эльдар', 'John', 'Barbara'); $studentsInsert = 'INSERT INTO students (id, name) VALUES '; $counter = count($studentsList); $marksInsert = 'INSERT INTO marks (id, student_id, val) VALUES '; $i = 0; foreach ($studentsList as $student) { $i++; $studentsInsert .= "\r\n"; $studentsInsert .= "($i, $student)"; if ($i < $counter) { $studentsInsert .= ','; } else { $studentsInsert .= ';'; } $qty = 5; for ($j = 0; $j <= $qty; $j++) { $id = (string)$i . (string)$j . (string)random_int(10000, 99999); $mark = random_int(2, 5); if ($mark === 3) $mark = random_int(3, 4); if ($mark === 2) $mark = random_int(2, 3); $mark = (string)$mark; $marksInsert .= "\r\n"; $marksInsert .= "($id, $i, $mark)"; $marksInsert .= ','; } } $marksInsert = rtrim($marksInsert, ','); $marksInsert .= ';'; echo $studentsInsert; echo "\r\n"; echo "\r\n"; echo "\r\n"; echo $marksInsert;
Show:  
Copy Clear