Jump to content

Display Data from phpMyAdmin Database to php Table


WyvernFrog

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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.