Guest User

Untitled

a guest
Jan 4th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $dbname = "timedrun";
  6. $conn = new mysqli($servername, $username, $password, $dbname);
  7.  
  8. if ($conn->connect_error) {
  9. die("Connection failed: " . $conn->connect_error);
  10. } else {
  11. echo "Connected successfully";
  12. }
  13. ?>
  14. <br>
  15. <?php
  16. $sql = "SELECT id, student, time, date, notes FROM times";
  17. $result = $conn->query($sql);
  18.  
  19.  
  20.  
  21. if ($result->num_rows > 0) {
  22. while($row = $result->fetch_assoc()) {
  23. echo "id: " . $row["id"]. " - Student: " . $row["student"]. " - Time: " . $row["time"]. " - Date: " .$row["date"]. " - Notes: " .$row["notes"]. "<br>";
  24. }
  25. } else {
  26. echo "0 results";
  27. }
  28. $conn->close();
  29. ?>
  30.  
  31. -- phpMyAdmin SQL Dump
  32. -- version 4.7.4
  33. -- https://www.phpmyadmin.net/
  34. --
  35. -- Host: 127.0.0.1
  36. -- Generation Time: Jan 04, 2018 at 01:40 PM
  37. -- Server version: 10.1.26-MariaDB
  38. -- PHP Version: 7.1.9
  39.  
  40. SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
  41. SET AUTOCOMMIT = 0;
  42. START TRANSACTION;
  43. SET time_zone = "+00:00";
  44.  
  45.  
  46. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  47. /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  48. /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  49. /*!40101 SET NAMES utf8mb4 */;
  50.  
  51. --
  52. -- Database: `timedrun`
  53. --
  54.  
  55. -- --------------------------------------------------------
  56.  
  57. --
  58. -- Table structure for table `times`
  59. --
  60.  
  61. CREATE TABLE `times` (
  62. `ID` int(11) NOT NULL,
  63. `student` int(11) DEFAULT NULL,
  64. `time` int(11) DEFAULT NULL,
  65. `date` date DEFAULT NULL,
  66. `notes` varchar(255) DEFAULT NULL
  67. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  68.  
  69. --
  70. -- Dumping data for table `times`
  71. --
  72.  
  73. INSERT INTO `times` (`ID`, `student`, `time`, `date`, `notes`) VALUES
  74. (1, 1, 60, '2017-12-28', 'First test'),
  75. (2, 2, 43, '2018-01-22', 'Second Test'),
  76. (3, 3, 75, '2018-01-12', 'Thrid Test');
  77.  
  78. --
  79. -- Indexes for dumped tables
  80. --
  81.  
  82. --
  83. -- Indexes for table `times`
  84. --
  85. ALTER TABLE `times`
  86. ADD PRIMARY KEY (`ID`),
  87. ADD KEY `student` (`student`);
  88.  
  89. --
  90. -- AUTO_INCREMENT for dumped tables
  91. --
  92.  
  93. --
  94. -- AUTO_INCREMENT for table `times`
  95. --
  96. ALTER TABLE `times`
  97. MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
  98.  
  99. --
  100. -- Constraints for dumped tables
  101. --
  102.  
  103. --
  104. -- Constraints for table `times`
  105. --
  106. ALTER TABLE `times`
  107. ADD CONSTRAINT `times_ibfk_1` FOREIGN KEY (`student`) REFERENCES `students` (`ID`);
  108. COMMIT;
  109.  
  110. /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  111. /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  112. /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
  113.  
  114. -- phpMyAdmin SQL Dump
  115. -- version 4.7.4
  116. -- https://www.phpmyadmin.net/
  117. --
  118. -- Host: 127.0.0.1
  119. -- Generation Time: Jan 04, 2018 at 01:42 PM
  120. -- Server version: 10.1.26-MariaDB
  121. -- PHP Version: 7.1.9
  122.  
  123. SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
  124. SET AUTOCOMMIT = 0;
  125. START TRANSACTION;
  126. SET time_zone = "+00:00";
  127.  
  128.  
  129. /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  130. /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  131. /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  132. /*!40101 SET NAMES utf8mb4 */;
  133.  
  134. --
  135. -- Database: `timedrun`
  136. --
  137.  
  138. -- --------------------------------------------------------
  139.  
  140. --
  141. -- Table structure for table `students`
  142. --
  143.  
  144. CREATE TABLE `students` (
  145. `ID` int(11) NOT NULL,
  146. `firstName` varchar(255) DEFAULT NULL,
  147. `lastName` varchar(255) DEFAULT NULL,
  148. `yearGroup` varchar(255) DEFAULT NULL,
  149. `house` varchar(255) DEFAULT NULL
  150. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  151.  
  152. --
  153. -- Dumping data for table `students`
  154. --
  155.  
  156. INSERT INTO `students` (`ID`, `firstName`, `lastName`, `yearGroup`, `house`) VALUES
  157. (1, 'Harold', 'Jones', 'E', 'K'),
  158. (2, 'Joe', 'Blogs', 'D', 'K'),
  159. (3, 'Cliff', 'Kloff', 'D', 'Tu');
  160.  
  161. --
  162. -- Indexes for dumped tables
  163. --
  164.  
  165. --
  166. -- Indexes for table `students`
  167. --
  168. ALTER TABLE `students`
  169. ADD PRIMARY KEY (`ID`);
  170.  
  171. --
  172. -- AUTO_INCREMENT for dumped tables
  173. --
  174.  
  175. --
  176. -- AUTO_INCREMENT for table `students`
  177. --
  178. ALTER TABLE `students`
  179. MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
  180. COMMIT;
  181.  
  182. /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  183. /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
  184. /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Add Comment
Please, Sign In to add comment