Jump to content


Photo

Display Data from phpMyAdmin Database to php Table

php

  • Please log in to reply
3 replies to this topic

#1 WyvernFrog

WyvernFrog
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 01 December 2016 - 11:31 PM

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);
?>

Attached Files


Edited by cyberRobot, 02 December 2016 - 01:40 PM.
added [code][/code] tags


#2 benanamen

benanamen
  • Members
  • PipPipPip
  • Master Coder
  • 1,250 posts

Posted 01 December 2016 - 11:48 PM

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, 01 December 2016 - 11:51 PM.

To save time, let's just assume I am never wrong.

The XY Problem
The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.


Make A Donation https://www.paypal.me/KevinRubio

#3 Psycho

Psycho
  • Moderators
  • Advanced Member
  • 11,676 posts
  • LocationCanada

Posted 02 December 2016 - 01:54 AM

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


The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

#4 benanamen

benanamen
  • Members
  • PipPipPip
  • Master Coder
  • 1,250 posts

Posted 02 December 2016 - 02:22 AM

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, 02 December 2016 - 02:23 AM.

To save time, let's just assume I am never wrong.

The XY Problem
The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.


Make A Donation https://www.paypal.me/KevinRubio




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users