WyvernFrog Posted December 1, 2016 Share Posted December 1, 2016 (edited) I need help getting the data from phpMyAdmin to display in a php table: <?php $con = mysqli_connect('localhost', 'root', 'root', 'music_database'); if(!$con) { die("Can not connect: " . mysqli_error($con)); } if(!mysqli_select_db($con, 'music_database')) { echo 'Database Not Selected!'; } $sql = "SELECT * FROM month1"; $query = mysqli_query($con, $sql); if (!$query) { // add this check. die('Invalid query: ' . mysqli_error($con)); } else{ echo "<table border=1> <tr> <th>Song Title</th> <th>Song Artist</th> <th>Song Album</th> <th>Year Released</th> <th>Month Played</th> <th>Day of the Week Played</th> <th>Date Played</th> <th>Time Played</th> </tr>"; while($record = mysqli_fetch_array($query)) { echo "<tr>"; echo "<td>" . $record['songtitle'] . "</td>"; echo "<td>" . $record['songartist'] . "</td>"; echo "<td>" . $record['songalbum'] . "</td>"; echo "<td>" . $record['yearreleased'] . "</td>"; echo "<td>" . $record['monthplayed'] . "</td>"; echo "<td>" . $record['dayplayed'] . "</td>"; echo "<td>" . $record['dateplayed'] . "</td>"; echo "<td>" . $record['timeplayed'] . "</td>"; echo "</tr>"; } echo "</table>"; } mysqli_close($con); ?> showrecords.php Edited December 2, 2016 by cyberRobot added [code][/code] tags Quote Link to comment https://forums.phpfreaks.com/topic/302659-display-data-from-phpmyadmin-database-to-php-table/ Share on other sites More sharing options...
benanamen Posted December 1, 2016 Share Posted December 1, 2016 (edited) Aside from your problem, stop with the ridiculous practice of outputting database errors to the user. The error messages are useless to the user and it is a security risk. I know you see at at all the sites you are copying your code from, but it is wrong. Edited December 1, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/302659-display-data-from-phpmyadmin-database-to-php-table/#findComment-1539944 Share on other sites More sharing options...
Psycho Posted December 2, 2016 Share Posted December 2, 2016 And what are the results of your script? Do you get errors, a blank page, or what? Quote Link to comment https://forums.phpfreaks.com/topic/302659-display-data-from-phpmyadmin-database-to-php-table/#findComment-1539950 Share on other sites More sharing options...
benanamen Posted December 2, 2016 Share Posted December 2, 2016 (edited) When asking for help on a forum, there are certain questions we expect to be answered to help you. Saying you need help doesn't help us to help you. 1. What have you tried - You posted your code, that's good 2. What was the result? 3. What is the expected result - In this case it is obvious Is error reporting turned on? Have you checked the error logs? Put this at the top of your script. Now what happens? error_reporting(-1); ini_set('display_errors', '1'); Edited December 2, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/302659-display-data-from-phpmyadmin-database-to-php-table/#findComment-1539951 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.