Jump to content
WyvernFrog

Display Data from phpMyAdmin Database to php Table

Recommended Posts

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 by cyberRobot
added [code][/code] tags

Share this post


Link to post
Share on other sites

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 by benanamen

Share this post


Link to post
Share on other sites

And what are the results of your script? Do you get errors, a blank page, or what?

Share this post


Link to post
Share on other sites

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 by benanamen

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.