MH90 Posted March 3, 2020 Share Posted March 3, 2020 (edited) I am new in PHP Programming , Please Help me. I have made a data table, then i have connected this table after that I have made a table in my index.php file . but i am facing problem to show data from data table in my index.php file, can you help me to solve this problem? <?php include "db.php"; ?> <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <title>Post Global Variable</title> </head> <body> <div class="row p-5"> <table class="table table-dark"> <thead> <tr> <th scope="col">#</th> <th scope="col">Name</th> <th scope="col">User Name</th> <th scope="col">Email Address</th> <th scope="col">Password</th> <th scope="col">Phone</th> <th scope="col">Join Date</th> <th scope="col">Action</th> </tr> </thead> <tbody> <?php $myQuery = "SELECT * FROM users"; $allUsers = mysqli_query ($db, $myQuery); while ($row = mysqli_fetch_assoc($allUsers)){ $id= $row['id']; $name= $row['name']; $userName= $row['userName']; $email= $row['email']; $password= $row['password']; $phone= $row['phone']; $join_date= $row['join_date']; ?> <tr> <th scope="row"><?php echo $id; ?></th> <td><?php echo $name; ?></td> <td><?php echo $userName; ?></td> <td><?php echo $email; ?></td> <td><?php echo $password; ?></td> <td><?php echo $phone; ?></td> <td><?php echo $join_date; ?></td> <td><a class="btn btn-success btn-sm" href="#" role="button">Update</a> <a class="btn btn-danger btn-sm" href="#" role="button">Delete</a> </td> </tr> <?php } ?> </tbody> </table> </div> <!-- Optional JavaScript --> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> </body> </html> Edited March 3, 2020 by MH90 Quote Link to comment Share on other sites More sharing options...
KHS Posted March 3, 2020 Share Posted March 3, 2020 (edited) Instead of $myQuery = "SELECT * FROM users"; try to put the name of the columns in your query, like this; $myQuery = "SELECT id, name, username, email, password, phone, join_date FROM users"; Let me know if it works. Edited March 3, 2020 by KHS Quote Link to comment Share on other sites More sharing options...
Barand Posted March 3, 2020 Share Posted March 3, 2020 @KHS I agree that SELECT * should not be used, but those "rows" you mentioned are "columns". Quote Link to comment Share on other sites More sharing options...
KHS Posted March 3, 2020 Share Posted March 3, 2020 (edited) @Barand Yes, that should be columns. I will edit it. Thanks. Edited March 3, 2020 by KHS Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 3, 2020 Share Posted March 3, 2020 As a newbie I highly recommend reading up on the "heredocs" use in the PHP manual. It will save you a lot of work when outputting your html table rows by avoiding having to switch in and out of php mode for every var. Still don't know what you "problem" is tho. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.