PHP - MySQL数据库显示在网页上但信息错误且位置错误

时间:2017-05-14 01:35:39

标签: php html mysql excel

我在MySQL中有一个数据库,但该表没有提供正确的信息。例如,当我运行我的代码时,我在excel中的表以及现在在MySQL中的表自动出现在我的网页上,但数据都是错误的,几乎都在错误的位置。唯一正确的部分是玩家编号和名称位于正确的位置,但即便如此,整个名称甚至都没有显示。然后位置列是所有随机字母,然后高度是重量,重量是年龄,依此类推。

另外,我的excel表当然有正确的所有东西。我只是不确定为什么在创建这个数据库时会输入错误的信息

这是我的整个PHP代码:

<?php        

     $db_conn = mysqli_connect("localhost", "root", "");
     if (!$db_conn)
        die("Unable to connect: " . mysqli_connect_error());  // die is similar to exit

     mysqli_query($db_conn, "CREATE DATABASE IF NO EXISTS bearsroster;");

     if (mysqli_query($db_conn, "CREATE DATABASE bearsroster;"))
        echo "Database ready<br>";
     else
        echo "Unable to create database: " . mysqli_error($db_conn) . "<br>";

    mysqli_select_db($db_conn, "bearsroster");

    $cmd = "CREATE TABLE sportDatabase (    number int(2) NOT NULL PRIMARY KEY,
                                            playerName char(50),
                                            position varchar(2),
                                            height char(3),
                                            weight int(3),
                                            age int(2),
                                            experience int(2),
                                            collegeName char(60)
                                        );";         //Creates the table
      mysqli_query($db_conn, $cmd);

      $cmd = "LOAD DATA LOCAL INFILE 'bearsRoster.csv' INTO TABLE sportDatabase FIELDS TERMINATED BY ',';";
      mysqli_query($db_conn, $cmd);

      echo "<h1>football database contents</h1>";
      $cmd = "SELECT * FROM sportDatabase";
      $records = mysqli_query($db_conn, $cmd); 

      echo( "<table border = 'black' align:'center'> 
                    <tr> 
                    <th>Number</th> 
                    <th>Player Name</th> 
                    <th>Position</th> 
                    <th>Height</th> 
                    <th>Weight</th> 
                    <th>Age</th>
                    <th>Experience</th> 
                    <th>College Name</th>
                    </tr>" . PHP_EOL  );

     //Prints out the table
    while($row = mysqli_fetch_array($records)){
        echo( "<tr> 
                <td id = 'yellow'>" . $row['number'] . "</td> 
                <td id = 'red'>" . $row['playerName'] . "</td> 
                <td id = 'red'>" . $row['position'] . "</td> 
                <td id = 'blue'>" . $row['height'] . "</td>
                <td id = 'blue'>". $row['weight'] . "</td>
                <td id = 'blue'>". $row['age'] . "</td>
                <td id = 'pink'>". $row['experience'] . "</td>
                <td id = 'pink'>". $row['collegeName'] . "</td>

                </tr>". PHP_EOL );
    }

enter image description here

enter image description here

0 个答案:

没有答案