i need to get the counting of the table rows in order as a column in column "N" also i need to make the column"N" width looks smaller than others columns i think i have done everything but this is the only point i couldn't achieved
the output should be as the picture :[source] https://i.stack.imgur.com/AlgZ5.png i hope you could help me guys, thank you here is my codes :
<html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <?php // DataBase connection $host = "localhost"; $user = "root"; $password = ""; $db = "worksheet9"; $con = mysqli_connect($host, $user, $password, $db); //verfiy Connection if( mysqli_connect_errno()){ echo " Connection Error:" . mysqli_connect_error(); } if(isset($_POST['submit'])){ $task=$_POST['task']; // insert sql query $sql = "INSERT INTO dolist (task) VALUES ('$task')"; $result=mysqli_query($con, $sql); // verify query if ($result) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($con); } } ?> <form method='POST'> <input type="text" name="task" id="task" required placeholder="add task" oninvalid="this.setCustomValidity('you must fill the task')" oninput="this.setCustomValidity('')"> <input type="submit"name="submit"value="add task" ><!-- comment --> </form> <table border="1"> <tr> <th> N </th> <th>ID </th> <th>task</th> <th>delete</th><!-- comment --> <th>update</th> </tr> <?php // Select sql query $sql = "SELECT ID,task FROM dolist"; $result= mysqli_query($con, $sql); while ($rows = mysqli_fetch_array($result)){ echo"<form method ='POST'>"; echo "<tr>"; echo "<td>" . "<input type='number' readonly name='number' value='" . $rows[''] . "'></td>"; echo "<td>" . "<input type='text' readonly name='id' value='" . $rows['ID'] . "'></td>"; echo "<td>" . "<input type='text' name='task' value= '" . $rows['task'] . "'></td>"; echo "<td>" . "<input type='submit' name='delete' value='x'>" . "</td>"; echo "<td>" . "<input type='submit' name='update' value='update'>" . "</td>"; echo"</tr>"; echo "</form>"; } if(isset($_POST['update'])){ $sql="UPDATE dolist SET task='$_POST[task]'WHERE ID=$_POST[id]"; $result=mysqli_query($con,$sql) or die(mysqli_connect_errno()); if($result){ echo "updated"; }else{ echo "update faild"; } } //perform only when the user click on Delete if(isset($_POST['delete'])){ $sql="DELETE FROM dolist WHERE ID=$_POST[id]"; $result=mysqli_query($con,$sql) or die(mysqli_connect_errno()); if($result){ echo "DELETED"; }else{ echo "delete faild"; } } ?> </table> </body> </html>
没有评论:
发表评论