Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在表中显示用户_Php_Mysql_Mysqli - Fatal编程技术网

Php 在表中显示用户

Php 在表中显示用户,php,mysql,mysqli,Php,Mysql,Mysqli,我遵循一个关于基本php表的教程向用户展示 我的问题是我的平台不支持MySQL,所以我把它改成了MySQL 第二个问题是,用户i在表上方显示 这是一幅更好描述的图像: 这是我正在使用的代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>View Rec

我遵循一个关于基本php表的教程向用户展示

我的问题是我的平台不支持MySQL,所以我把它改成了MySQL

第二个问题是,用户i在表上方显示

这是一幅更好描述的图像:

这是我正在使用的代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
        <title>View Records</title>
</head>
<body>

<?php
/* 
        VIEW-PAGINATED.PHP
        Displays all data from 'players' table
        This is a modified version of view.php that includes pagination
*/

        // connect to the database
        include('config.php');

        // number of results to show per page
        $per_page = 1;

        // figure out the total pages in the database
        $result = mysqli_query($connecDB,"SELECT * FROM users");
        $total_results = mysqli_num_rows($result);
        $total_pages = ceil($total_results / $per_page);

        // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
        if (isset($_GET['page']) && is_numeric($_GET['page']))
        {
                $show_page = $_GET['page'];

                // make sure the $show_page value is valid
                if ($show_page > 0 && $show_page <= $total_pages)
                {
                        $start = ($show_page -1) * $per_page;
                        $end = $start + $per_page; 
                }
                else
                {
                        // error - show first set of results
                        $start = 0;
                        $end = $per_page; 
                }               
        }
        else
        {
                // if page isn't set, show first set of results
                $start = 0;
                $end = $per_page; 
        }

        // display pagination

        echo "<p> | <b>View Page:</b> ";
        for ($i = 1; $i <= $total_pages; $i++)
        {
                echo "<a href='admin_user_list.php?page=$i'>$i</a> ";
        }
        echo "</p>";

        // display data in table
        echo "<table border='1' cellpadding='10'>";
        echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";

        // loop through results of database query, displaying them in the table 
        for ($i = $start; $i < $end; $i++)
        {
                // make sure that PHP doesn't try to show results that don't exist
                if ($i == $total_results) { break; }

                // echo out the contents of each row into a table
                echo "<tr>";

                 while($row = mysqli_fetch_assoc($result)) {
                 $id = $row['id'];
                 $fname = $row['first_name']; 

                 echo  $id; 
                 echo $fname;


                 }

                   // echo '<td><a href="edit.php?id=' . mysql_result($result, $i, 'id') . '">Edit</a></td>';
                   // echo '<td><a href="delete.php?id=' . mysqli_result($result, $i, 'id') . '">Delete</a></td>';
                echo "</tr>"; 
        }
        // close table>
        echo "</table>"; 

        // pagination

?>
<p><a href="admin/admin_user_add.php">Add a new record</a></p>

</body>
</html>

查看记录
编辑附录#3

如果以后要添加额外的单元格,请遵循相同的约定

// echo out the contents of each row into a table
echo "<tr>";

while($row = mysqli_fetch_assoc($result)) {
    $id = $row['id'];
    $fname = $row['first_name']; 
    $lname = $row['last_name'];

    echo "<tr><td>"; // do not modify
    echo  $id; 
    echo "</td>"; // do not modify
    echo "<td>";
    echo $fname;
    echo "<td>";
    echo $lname;
    // there should not be anything below this
    // besides the echo "</td></tr>";
    echo "</td></tr>"; // do not modify
}

编辑2

查看记录


原始答案 请尝试下面的完整代码

我在
echo”中添加了一个
中的
echo”“


查看记录

您需要将您的
echo'在循环上方(外部)。注意
echo''在教程中,它是否在
while
循环
while($row=mysql\u fetch\u array($result))
之外?好吧,也一样。见我的第一条评论。我真的不想为这一次买我的“开罐器”。非常感谢您的回复,因为您注意到我没有更改echo“”的位置;这与教程中的内容是一样的,如果我误解了你,真的很抱歉,这是最奇怪的。我想当时我错了。我搞不懂。你有
echo''尝试执行
echo”“然后你有
echo''尝试
echo”“我尝试过了它仍然是一样的id上的每件事我会有3个以上,但我会在计算出这一个后添加它们真的很感谢你的帮助不客气。在
编辑1
@user3029453下重新加载我的答案-希望它能起作用。您可能需要查看源代码以查看HTML的布局,以便更好地解决问题。请重新加载它,我想我可能犯了一个小错误@USER3029453这是工作,但它不是单独的用户表单id,我想我已经修复了它。为
编辑2
@user3029453重新加载
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
        <title>View Records</title>
</head>
<body>

<?php
/* 
        VIEW-PAGINATED.PHP
        Displays all data from 'players' table
        This is a modified version of view.php that includes pagination
*/

        // connect to the database
        include('config.php');


        // number of results to show per page
        $per_page = 1;

        // figure out the total pages in the database
        $result = mysqli_query($db,"SELECT * FROM animals");
        $total_results = mysqli_num_rows($result);
        $total_pages = ceil($total_results / $per_page);

        // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
        if (isset($_GET['page']) && is_numeric($_GET['page']))
        {
                $show_page = $_GET['page'];

                // make sure the $show_page value is valid
                if ($show_page > 0 && $show_page <= $total_pages)
                {
                        $start = ($show_page -1) * $per_page;
                        $end = $start + $per_page; 
                }
                else
                {
                        // error - show first set of results
                        $start = 0;
                        $end = $per_page; 
                }               
        }
        else
        {
                // if page isn't set, show first set of results
                $start = 0;
                $end = $per_page; 
        }

        // display pagination

        echo "<p> | <b>View Page:</b> ";
        for ($i = 1; $i <= $total_pages; $i++)
        {
                echo "<a href='admin_user_list.php?page=$i'>$i</a> ";
        }
        echo "</p>";

        // display data in table
        echo "<table border='1' cellpadding='10'>";
        // echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";
        echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th>";

        // loop through results of database query, displaying them in the table 
        for ($i = $start; $i < $end; $i++)
        {
                // make sure that PHP doesn't try to show results that don't exist
                if ($i == $total_results) { break; }

                // echo out the contents of each row into a table
                 echo "<tr>";

                 while($row = mysqli_fetch_assoc($result)) {
                 $id = $row['id'];
                 $fname = $row['name']; 
                 $lname = $row['lname'];

                  echo "<tr><td>";
                 echo  $id; 
                  echo "</td>"; 
                  echo "<td>";
                 echo $fname;
                  echo "<td>";
                 echo $lname;
                  echo "</td></tr>"; 

                 }

                   // echo '<td><a href="edit.php?id=' . mysql_result($result, $i, 'id') . '">Edit</a></td>';
                   // echo '<td><a href="delete.php?id=' . mysqli_result($result, $i, 'id') . '">Delete</a></td>';
         echo "</td></tr>"; 
        }
        // close table>
        echo "</table>"; 

        // pagination

?>
<p><a href="admin/admin_user_add.php">Add a new record</a></p>

</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
        <title>View Records</title>
</head>
<body>

<?php
/* 
        VIEW-PAGINATED.PHP
        Displays all data from 'players' table
        This is a modified version of view.php that includes pagination
*/

        // connect to the database
        include('config.php');

        // number of results to show per page
        $per_page = 1;

        // figure out the total pages in the database
        $result = mysqli_query($connecDB,"SELECT * FROM users");
        $total_results = mysqli_num_rows($result);
        $total_pages = ceil($total_results / $per_page);

        // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
        if (isset($_GET['page']) && is_numeric($_GET['page']))
        {
                $show_page = $_GET['page'];

                // make sure the $show_page value is valid
                if ($show_page > 0 && $show_page <= $total_pages)
                {
                        $start = ($show_page -1) * $per_page;
                        $end = $start + $per_page; 
                }
                else
                {
                        // error - show first set of results
                        $start = 0;
                        $end = $per_page; 
                }               
        }
        else
        {
                // if page isn't set, show first set of results
                $start = 0;
                $end = $per_page; 
        }

        // display pagination

        echo "<p> | <b>View Page:</b> ";
        for ($i = 1; $i <= $total_pages; $i++)
        {
                echo "<a href='admin_user_list.php?page=$i'>$i</a> ";
        }
        echo "</p>";

        // display data in table
        echo "<table border='1' cellpadding='10'>";
        // echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";
        echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th>";

        // loop through results of database query, displaying them in the table 
        for ($i = $start; $i < $end; $i++)
        {
                // make sure that PHP doesn't try to show results that don't exist
                if ($i == $total_results) { break; }

                // echo out the contents of each row into a table
                 echo "<tr>";

                 while($row = mysqli_fetch_assoc($result)) {
                 $id = $row['id'];
                 $fname = $row['first_name']; 

                 echo "<td>";
                 echo  $id; 
                 echo "</td>";
                 echo "<td>";
                 echo $fname;
                 echo "</td>"; 

                 }

                   // echo '<td><a href="edit.php?id=' . mysql_result($result, $i, 'id') . '">Edit</a></td>';
                   // echo '<td><a href="delete.php?id=' . mysqli_result($result, $i, 'id') . '">Delete</a></td>';
         echo "</tr>"; 
        }
        // close table>
        echo "</table>"; 

        // pagination

?>
<p><a href="admin/admin_user_add.php">Add a new record</a></p>

</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
        <title>View Records</title>
</head>
<body>

<?php
/* 
        VIEW-PAGINATED.PHP
        Displays all data from 'players' table
        This is a modified version of view.php that includes pagination
*/

        // connect to the database
        include('config.php');

        // number of results to show per page
        $per_page = 1;

        // figure out the total pages in the database
        $result = mysqli_query($connecDB,"SELECT * FROM users");
        $total_results = mysqli_num_rows($result);
        $total_pages = ceil($total_results / $per_page);

        // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
        if (isset($_GET['page']) && is_numeric($_GET['page']))
        {
                $show_page = $_GET['page'];

                // make sure the $show_page value is valid
                if ($show_page > 0 && $show_page <= $total_pages)
                {
                        $start = ($show_page -1) * $per_page;
                        $end = $start + $per_page; 
                }
                else
                {
                        // error - show first set of results
                        $start = 0;
                        $end = $per_page; 
                }               
        }
        else
        {
                // if page isn't set, show first set of results
                $start = 0;
                $end = $per_page; 
        }

        // display pagination

        echo "<p> | <b>View Page:</b> ";
        for ($i = 1; $i <= $total_pages; $i++)
        {
                echo "<a href='admin_user_list.php?page=$i'>$i</a> ";
        }
        echo "</p>";

        // display data in table
        echo "<table border='1' cellpadding='10'>";
        // echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";
        echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th>";

        // loop through results of database query, displaying them in the table 
        for ($i = $start; $i < $end; $i++)
        {
                // make sure that PHP doesn't try to show results that don't exist
                if ($i == $total_results) { break; }

                // echo out the contents of each row into a table
                 echo "<tr>";

                 while($row = mysqli_fetch_assoc($result)) {
                 $id = $row['id'];
                 $fname = $row['first_name']; 

                 echo "<td>";
                 echo  $id; 
                 echo $fname;
                 echo "</td>"; 

                 }

                   // echo '<td><a href="edit.php?id=' . mysql_result($result, $i, 'id') . '">Edit</a></td>';
                   // echo '<td><a href="delete.php?id=' . mysqli_result($result, $i, 'id') . '">Delete</a></td>';
         echo "</tr>"; 
        }
        // close table>
        echo "</table>"; 

        // pagination

?>
<p><a href="admin/admin_user_add.php">Add a new record</a></p>

</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
        <title>View Records</title>
</head>
<body>

<?php
/* 
        VIEW-PAGINATED.PHP
        Displays all data from 'players' table
        This is a modified version of view.php that includes pagination
*/

        // connect to the database
        include('config.php');

        // number of results to show per page
        $per_page = 1;

        // figure out the total pages in the database
        $result = mysqli_query($connecDB,"SELECT * FROM users");
        $total_results = mysqli_num_rows($result);
        $total_pages = ceil($total_results / $per_page);

        // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
        if (isset($_GET['page']) && is_numeric($_GET['page']))
        {
                $show_page = $_GET['page'];

                // make sure the $show_page value is valid
                if ($show_page > 0 && $show_page <= $total_pages)
                {
                        $start = ($show_page -1) * $per_page;
                        $end = $start + $per_page; 
                }
                else
                {
                        // error - show first set of results
                        $start = 0;
                        $end = $per_page; 
                }               
        }
        else
        {
                // if page isn't set, show first set of results
                $start = 0;
                $end = $per_page; 
        }

        // display pagination

        echo "<p> | <b>View Page:</b> ";
        for ($i = 1; $i <= $total_pages; $i++)
        {
                echo "<a href='admin_user_list.php?page=$i'>$i</a> ";
        }
        echo "</p>";

        // display data in table
        echo "<table border='1' cellpadding='10'>";
        echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";

        // loop through results of database query, displaying them in the table 
        for ($i = $start; $i < $end; $i++)
        {
                // make sure that PHP doesn't try to show results that don't exist
                if ($i == $total_results) { break; }

                // echo out the contents of each row into a table
                echo "<tr><td>";

                 while($row = mysqli_fetch_assoc($result)) {
                 $id = $row['id'];
                 $fname = $row['first_name']; 

                 echo  $id; 
                 echo $fname;

                 }

                   // echo '<td><a href="edit.php?id=' . mysql_result($result, $i, 'id') . '">Edit</a></td>';
                   // echo '<td><a href="delete.php?id=' . mysqli_result($result, $i, 'id') . '">Delete</a></td>';
                echo "</td></tr>"; 
        }
        // close table>
        echo "</table>"; 

        // pagination

?>
<p><a href="admin/admin_user_add.php">Add a new record</a></p>

</body>
</html>