Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How To Force MySql With Php To Show Final Row Only?

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 586
    Answer it

    Buds!

    How to code so php forces mysql to show only the final row of the column ?
    The followings are how I coded (2 copied youtube tuts) to show all rows to allow user to delete multiple rows:SAMPLE 1

    1. [php]
    2. <?php
    3. session_start();
    4. require "conn.php";
    5. require "site_details.php"; ?>
    6.  
    7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    8. <html>
    9. <head>
    10. <title>Follow Users</title>
    11. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    12. </head>
    13. <body>
    14. <form name="form" action="" method="post">
    15. <table border=1 cellpadding=1 cellspacing=1>
    16. <tr>
    17. <th>Id</th>
    18. <th>Username</th>
    19. <th>Password</th>
    20. <th>Email</th>
    21. <th>Delete</th>
    22. </tr>
    23. <?php
    24. $res=mysqli_query($conn,"SELECT * FROM users");
    25. while($row=mysqli_fetch_array($res))
    26. {
    27. echo "<tr>";
    28. echo "<td>"; ?> <input type="checkbox" name="num[]" class="other" value="<?php echo $row["id"]; ?>" /> <?php echo "</td>";
    29. echo "<td>"; echo $row["ids"]; echo "</td>";
    30. echo "<td>"; echo $row["usernames"]; echo "</td>";
    31. echo "<td>"; echo $row["passwords"]; echo "</td>";
    32. echo "<td>"; echo $row["emails"]; echo "</td>";
    33. echo "</tr>";
    34. }
    35. ?>
    36. </table>
    37. <input type="submit" name="submit" value="delete selected">
    38. </form>
    39. <?php
    40. if(isset($_POST["submit"]))
    41. {
    42. $box=$_POST['num'];
    43. while (list ($key,$val) = @each ($box))
    44. {
    45. mysqli_query($conn,"DELETE FROM users WHERE id='$val'");
    46. }
    47. ?>
    48. <script type="text/javascript">
    49. window.location.href=window.location.href;
    50. </script>
    51. <?php
    52. }
    53. ?>
    54.  
    55. </body>
    56. </html>
    57. [/php]

     

    SAMPLE 2:

    1. [php]
    2.  
    3. <?php
    4. session_start();
    5. require "conn.php";
    6. require "site_details.php"; ?>
    7.  
    8. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    9. <html>
    10. <head>
    11. <title>Follow Users</title>
    12. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    13. </head>
    14. <body>
    15. <table border=1 cellpadding=1 cellspacing=1>
    16. <tr>
    17. <th>Id</th>
    18. <th>Username</th>
    19. <th>Password</th>
    20. <th>Email</th>
    21. <th>Delete</th>
    22. </tr>
    23. <?php
    24. $sql = "SELECT * FROM users";
    25. $result = mysqli_query($conn,$sql);
    26. while($row = mysqli_fetch_array($result))
    27. {
    28. echo "<tr>";
    29. echo "<td>".$row['ids']."</td>";
    30. echo "<td>".$row['usernames']."</td>";
    31. echo "<td>".$row['passwords']."</td>";
    32. echo "<td>".$row['emails']."</td>";
    33. echo "<td><a href=delete2b.php?id=".$row['ids'].">Delete</a></td>";
    34. }
    35.  
    36. ?>
    37. </table>
    38. </body>
    39. </html>
    40.  
    41. [/php]

     

 1 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: