MySQL:链接未使用while循环显示在正确的列中

时间:2014-07-07 16:38:16

标签: php mysql

我在MySQL循环中遇到问题。 我正在尝试建立一个链接到活动和取消激活数据库中的用户。

我尝试使用while循环来显示db中的所有用户,然后在下一个链接中放置一个链接。

但问题是链接没有显示在其正确的用户旁边,我还尝试为链接分配ID和用户名,并显示正确的信息。

该链接显示正确用户下方1步。

Here is img

这是我的代码。

    require('./connect.php');
    $query = "SELECT * FROM users ORDER BY id ASC";
    $result = mysqli_query($con, $query);
    $numrows = mysqli_num_rows($result);
    if ($numrows > 0) {
        echo '<table class="table" border="1">
        <tr style="background-color: #0DF; color: #222; font-weight:bold;">
            <td>ID:</td>
            <td>User Name:</td>
            <td>Email:</td>
            <td>First Name:</td>
            <td>Last Name:</td>
            <td>Domain:</td>
            <td>Country:</td>
            <td>Phone:</td>
            <td>Plan:</td>
            <td>Duration:</td>
            <td>Payable:</td>
            <td>Paid Date:</td>
            <td>Active Plan:</td>
            <td>Active:</td>
            <td>Register Date:</td>
        </tr>';
        while ( $row = mysqli_fetch_assoc($result) ) {
            $dbid = $row['id'];
            $dbuser = $row['username'];
            $dbemail = $row['email'];
            $dbfname = $row['first_name'];
            $dblname = $row['last_name'];
            $dbdomain = $row['domain'];
            $dbcountry = $row['country'];
            $dbphone = $row['phone'];
            $dbplan = $row['plan'];
            $dbduration = $row['duration'];
            $dbpayable = $row['payable'];
            $dbpaid_date = $row['paid_date'];
            $dbactive_plan = $row['active_plan'];
            $dbactive = $row['active'];
            $dbdate = $row['date'];
            echo '
            <tr>
                <td>'.$dbid.'</td>
                <td>'.$dbuser.' <a href="http://www.mydomain.com/admin.php?id='.$dbid.'">Delete</a></td>
                <td>'.$dbemail.'</td>
                <td>'.$dbfname.'</td>
                <td>'.$dblname.'</td>
                <td>'.$dbdomain.'</td>
                <td>'.$dbcountry.'</td>
                <td>'.$dbphone.'</td>
                <td>'.$dbplan.'</td>
                <td>'.$dbduration.'</td>
                <td>'.$dbpayable.'</td>
                <td>'.$dbpaid_date.'</td>
                <td>'.$dbactive_plan.' '.$changeStatus.'</td>
                <td>'.$dbactive.'</td>
                <td>'.$dbdate.'</td>
            </tr>';

            if ( $dbactive_plan == 0) {
                $status = "Activate";
                $changeStatus = '<a href="http://www.mydomain.com/admin.php?status=1&user='.$dbuser.'">'.$status.'</a>';
            }
            else {
                $status = "Deactivate";
                $changeStatus = '<a href="http://www.mydomain.com/admin.php?status=0&user='.$dbuser.'">'.$status.'</a>';
            }
        }//while loop
        echo '</table>';

1 个答案:

答案 0 :(得分:0)

require('./connect.php');
    $query = "SELECT * FROM users ORDER BY id ASC";
    $result = mysqli_query($con, $query);
    $numrows = mysqli_num_rows($result);
    if ($numrows > 0) {
        echo '<table class="table" border="1">
        <tr style="background-color: #0DF; color: #222; font-weight:bold;">
            <td>ID:</td>
            <td>User Name:</td>
            <td>Email:</td>
            <td>First Name:</td>
            <td>Last Name:</td>
            <td>Domain:</td>
            <td>Country:</td>
            <td>Phone:</td>
            <td>Plan:</td>
            <td>Duration:</td>
            <td>Payable:</td>
            <td>Paid Date:</td>
            <td>Active Plan:</td>
            <td>Active:</td>
            <td>Register Date:</td>
        </tr>';
        while ( $row = mysqli_fetch_assoc($result) ) {
            $dbid = $row['id'];
            $dbuser = $row['username'];
            $dbemail = $row['email'];
            $dbfname = $row['first_name'];
            $dblname = $row['last_name'];
            $dbdomain = $row['domain'];
            $dbcountry = $row['country'];
            $dbphone = $row['phone'];
            $dbplan = $row['plan'];
            $dbduration = $row['duration'];
            $dbpayable = $row['payable'];
            $dbpaid_date = $row['paid_date'];
            $dbactive_plan = $row['active_plan'];
            $dbactive = $row['active'];
            $dbdate = $row['date'];
            if ( $dbactive_plan == 0) {
                $status = "Activate";
                $changeStatus = '<a href="http://www.mydomain.com/admin.php?status=1&user='.$dbuser.'">'.$status.'</a>';
            }
            else {
                $status = "Deactivate";
                $changeStatus = '<a href="http://www.mydomain.com/admin.php?status=0&user='.$dbuser.'">'.$status.'</a>';
            }
            echo '
            <tr>
                <td>'.$dbid.'</td>
                <td>'.$dbuser.' <a href="http://www.mydomain.com/admin.php?id='.$dbid.'">Delete</a></td>
                <td>'.$dbemail.'</td>
                <td>'.$dbfname.'</td>
                <td>'.$dblname.'</td>
                <td>'.$dbdomain.'</td>
                <td>'.$dbcountry.'</td>
                <td>'.$dbphone.'</td>
                <td>'.$dbplan.'</td>
                <td>'.$dbduration.'</td>
                <td>'.$dbpayable.'</td>
                <td>'.$dbpaid_date.'</td>
                <td>'.$dbactive_plan.' '.$changeStatus.'</td>
                <td>'.$dbactive.'</td>
                <td>'.$dbdate.'</td>
            </tr>';
        }//while loop
        echo '</table>';