如何在while循环外添加2个或更多表?

时间:2018-10-21 05:25:28

标签: php

将标题放在while循环之外,可以得到一张桌子,如下所示:

<?php
session_start();

include_once 'admin_navmenu.php';
$premium = 1;

$sql = "SELECT * FROM users WHERE premium = ?;";

$stmt = mysqli_stmt_init($conn);

if (!mysqli_stmt_prepare($stmt, $sql)) {
   echo 'SQL error';

} else {
    mysqli_stmt_bind_param($stmt, "i", $premium);
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    $resultCheck = mysqli_num_rows($result);
    if ($resultCheck < 1) {
        echo 'There are no premium users!';

    }

    echo '<table class="user_information_premium">

                      <tr>
                      <th colspan="2" class="update_title">General Information: Premium Membership Users
                      </tr>';

    while($row = mysqli_fetch_assoc($result)) {
       if ($row['admin'] == 0) {
        $admin = 'No';
    } else {
        $admin = 'Yes';
    }

    if ($row['moderator'] == 0) {
        $moderator = 'No';
    } else {
        $moderator = 'Yes';
    }

    if ($row['user_activate'] == 0) {
        $activate = 'No';
    } else {
        $activate = 'Yes';
    }

    if ($row['premium'] == 0) {
        $premium = 'No';
    } else {
        $premium = 'Yes';
    }





                      echo '
                      <tr>
                      <th>User ID:</th><td>',htmlspecialchars($row['user_id']),'</td>
                      </tr>
                      <tr>
                      <th>First Name:</th><td>',htmlspecialchars($row['user_first']),'</td>
                      </tr>
                      <tr>
                      <th>Last Name</th><td>',htmlspecialchars($row['user_last']),'</td>
                      </tr>
                      <tr>
                      <th>Email Address:</th><td>',htmlspecialchars($row['user_email']),'</td>
                      </tr>
                      <tr>
                      <th>User ID:</th><td>',htmlspecialchars($row['user_uid']),'</td>
                      </tr>
                      <tr>
                      <th>Country Status:</th><td>',htmlspecialchars($row['user_country']),'</td>
                      </tr>
                      <tr>
                      <th>Admin Status:</th><td>',htmlspecialchars($admin),'</td>
                      </tr>
                      <tr>
                      <th>Moderator Status:</th><td>',htmlspecialchars($moderator),'</td>
                      </tr>
                      <tr>
                      <th>Free Lesson Status:</th><td>',htmlspecialchars($row['freelesson']),'</td>
                      </tr>
                      <tr>
                      <th>Date Joined Status:</th><td>',htmlspecialchars($row['datejoined']),'</td>
                      </tr>
                      <tr>
                      <th>User Session Status(Last Login):</th><td>',htmlspecialchars($row['user_session']),'</td>
                      </tr>
                      <tr>
                      <th>Activate Non Premium Status:</th><td>',htmlspecialchars($activate),'</td>
                      </tr>
                      <tr>
                      <th>Premium Status:</th><td>',htmlspecialchars($premium),'</td>
                      </tr>';

                  }
                   echo '</table>';
              }

但是如何在while循环外仍然有3个标题的同时做3个单独的表?另外,使用','和'..'有什么区别?当您具有href标记之类的链接时,是否会使用“ ..”?对于上面的代码,我一直在将','与htmlspecialchars一起使用,这是正确的格式吗?

我尝试了以下更新的代码,并认为它应该可以工作,但是看起来很奇怪,如下图所示:

<!DOCTYPE html>
<html>
<head>
   <title></title>
   <meta charset="utf-8">
   <link rel="stylesheet" type="text/css" href="style.css">
   <link href="https://fonts.googleapis.com/css?family=Righteous" rel="stylesheet">
   <link href="https://fonts.googleapis.com/css?family=Catamaran" rel="stylesheet">

</head>
<body>





<?php

 include_once 'header2.php';

 $limit = 1;

if(!isset($_SESSION['u_uid'])) {
 echo "<meta http-equiv='refresh' content='0;url=index.php?update=notlogin'>";
  exit();
} else {
  include_once 'includes/dbh.php';





                           //Created a template
                            $sql = "SELECT * FROM users WHERE user_uid = ? LIMIT ?;";
                            //Create a prepared statement

                            $stmt = mysqli_stmt_init($conn);
                            //Prepare the prepared statement
                            if (!mysqli_stmt_prepare($stmt, $sql)) {
                                echo 'SQL statement failed';
                            } else {
                                 //Bind parameters to the placeholder
                                 mysqli_stmt_bind_param($stmt, "si", $_SESSION['u_uid'], $limit);
                                 //Run parameters inside database
                                 mysqli_stmt_execute($stmt);

                                    $result = mysqli_stmt_get_result($stmt);
                                    $resultcheck = mysqli_num_rows($result);


                                 if ($resultCheck > 0)  {




                                   $sql2 = "SELECT * FROM memberships WHERE user_uid = ? LIMIT ?;";
                            //Create a prepared statement

                            $stmt = mysqli_stmt_init($conn);
                            //Prepare the prepared statement
                            if (!mysqli_stmt_prepare($stmt, $sql2)) {
                                echo 'SQL statement failed';
                            } else {
                                 //Bind parameters to the placeholder
                                 mysqli_stmt_bind_param($stmt, "si", $_SESSION['u_uid'], $limit);
                                 //Run parameters inside database
                                 mysqli_stmt_execute($stmt);

                                    $result2 = mysqli_stmt_get_result($stmt);

                                    echo '<table class="update_information">

                                          <tr >
                                          <th class="update_title">Level 1 Subscriptionplan:</th>
                                          </tr>';

                                    echo '<table class="update_information2">

                                          <tr >
                                          <th class="update_title">Level 2 Subscriptionplan:</th>
                                          </tr>';



                                   echo '<table class="update_information3">

                                          <tr >
                                          <th class="update_title">Level 3 Subscriptionplan:</th>
                                          </tr>';



                                 while ($row2 = mysqli_fetch_assoc($result2))  {

                                    // Level 1 information

                                    if($row2['subscriptionplan'] == null) {
                                        $row2['subscriptionplan'] = 'None';
                                    } else {
                                        $row2['subscriptionplan'];

                                    }

                                 if ($row2['feesmonthly'] == 0) {
                                    $feesmonthly = 'None';
                                 } else {
                                    $feesmonthly = 100;
                                 }

                                 if ($row2['feesyearly'] == 0) {
                                    $feesyearly = 'None';
                                 } else {
                                    $feesyearly = 800;
                                 }

                                 if ($row2['emailreminder'] == 0) {
                                    $row2['emailreminder'] = 'No';
                                 } else {
                                    $row2['emailreminder'];
                                }

                                 if ($row2['overdue'] == 0) {
                                    $row2['overdue'] = 'No';
                                 } else {
                                    $row2['overdue'] = 'Yes';
                                 }

                                 if ($row2['subscriptionplandate'] == null) {
                                    $row2['subscriptionplandate'] = 'None';
                                 } else {
                                    $row2['subscriptionplandate'];
                                 }

                                 if ($row2['paid'] == null) {
                                    $row2['paid'] = 'Not Paid';
                                 } else {
                                    $row2['paid'] = 'Paid';
                                 }

                                 if ($row2['expirydate'] == null) {
                                    $row2['expirydate'] = 'None';
                                 } else {
                                    $row2['expirydate'];
                                 }

                                 if ($row2['paidbydate'] == null) {
                                    $row2['paidbydate'] = 'None';
                                 } else {
                                    $row2['paidbydate'];
                                 }

                                 if ($row2['activate'] == 0) {
                                    $row2['activate'] = 'Not Activated';
                                 } else {
                                    $row2['activate'] = 'Actviated';
                                }

                                // Level 2 information

                                 if($row2['subscriptionplan2'] == null) {
                                        $row2['subscriptionplan2'] = 'None';
                                    } else {
                                        $row2['subscriptionplan2'];

                                    }

                                 if ($row2['feesmonthly2'] == 0) {
                                    $feesmonthly2 = 'None';
                                 } else {
                                    $feesmonthly2 = 150;
                                 }

                                 if ($row2['feesyearly2'] == 0) {
                                    $feesyearly2 = 'None';
                                 } else {
                                    $feesyearly2 = 1300;
                                 }

                                 if ($row2['emailreminder2'] == 0) {
                                    $row2['emailreminder2'] = 'No';
                                 } else {
                                    $row2['emailreminder2'];
                                }

                                 if ($row2['overdue2'] == 0) {
                                    $row2['overdue2'] = 'No';
                                 } else {
                                    $row2['overdue2'] = 'Yes';
                                 }

                                 if ($row2['subscriptionplandate2'] == null) {
                                    $row2['subscriptionplandate2'] = 'None';
                                 } else {
                                    $row2['subscriptionplandate2'];
                                 }

                                 if ($row2['paid2'] == null) {
                                    $row2['paid2'] = 'Not Paid';
                                 } else {
                                    $row2['paid2'] = 'Paid';
                                 }

                                 if ($row2['expirydate2'] == null) {
                                    $row2['expirydate2'] = 'None';
                                 } else {
                                    $row2['expirydate2'];
                                 }

                                 if ($row2['paidbydate2'] == null) {
                                    $row2['paidbydate2'] = 'None';
                                 } else {
                                    $row2['paidbydate2'];
                                 }

                                 if ($row2['activate2'] == 0) {
                                    $row2['activate2'] = 'Not Activated';
                                 } else {
                                    $row2['activate2'] = 'Activated';
                                }

                                // Level 3 Information

                                if($row2['subscriptionplan3'] == null) {
                                        $row2['subscriptionplan3'] = 'None';
                                    } else {
                                        $row2['subscriptionplan3'];

                                    }

                                if ($row2['feesmonthly3'] == 0) {
                                    $feesmonthly3 = 'None';
                                 } else {
                                    $feesmonthly3 = 200;
                                 }

                                 if ($row2['feesyearly3'] == 0) {
                                    $feesyearly3 = 'None';
                                 } else {
                                    $feesyearly3 = 1800;
                                 }

                                 if ($row2['emailreminder3'] == 0) {
                                    $row2['emailreminder3'] = 'No';
                                 } else {
                                    $row2['emailreminder3'];
                                }

                                 if ($row2['overdue'] == 0) {
                                    $row2['overdue3'] = 'No';
                                 } else {
                                    $row2['overdue3'] = 'Yes';
                                 }

                                 if ($row2['subscriptionplandate3'] == null) {
                                    $row2['subscriptionplandate3'] = 'None';
                                 } else {
                                    $row2['subscriptionplandate3'];
                                 }

                                 if ($row2['paid3'] == null) {
                                    $row2['paid3'] = 'Not Paid';
                                 } else {
                                    $row2['paid3'] = 'Paid';
                                 }

                                 if ($row2['expirydate3'] == null) {
                                    $row2['expirydate3'] = 'None';
                                 } else {
                                    $row2['expirydate3'];
                                 }

                                 if ($row2['paidbydate3'] == null) {
                                    $row2['paidbydate3'] = 'None';
                                 } else {
                                    $row2['paidbydate3'];
                                 }

                                 if ($row2['activate3'] == 0) {
                                    $row2['activate3'] = 'Not Activated';
                                 } else {
                                    $row2['activate3'] = 'Activated';
                                }



                      echo '
                      <tr >
                      <th>Subscriptionplan:</th><td>',htmlspecialchars($row2['subscriptionplan']),'</td>
                      </tr>
                      <tr>
                      <th>Subscriptionplan Date:</th><td>',htmlspecialchars($row2['subscriptionplandate2']),'</td>
                      </tr>
                      <tr>
                      <th>Monthly Fees:</th><td>',htmlspecialchars($feesmonthly),'</td>
                      </tr>
                      <tr>
                      <th>Yearly Fees:</th><td>',htmlspecialchars($feesyearly),'</td>
                      </tr>
                      <tr>
                      <th>Payment Status:</th><td>',htmlspecialchars($row2['paid2']),'</td>
                      </tr>
                      <tr>
                      <th>Expiry Date:</th><td>',htmlspecialchars($row2['expirydate2']),'</td>
                      </tr>
                      <tr>
                      <th>Payment Due Date: </th><td>',htmlspecialchars($row2['paidbydate2']),'</td>
                      </tr>
                      <tr>
                      <th>Email Reminder Status: </th><td>',htmlspecialchars($row2['emailreminder2']),'</td>
                      </tr>
                      <tr>
                      <th>Over Due Status: </th><td>',htmlspecialchars($row2['overdue2']),'</td>
                      </tr>
                       <tr>
                      <th>Activate Status: </th><td>',htmlspecialchars($row2['activate2']),'</td>
                      </tr>';


                      echo '
                      <tr >
                      <th>Subscriptionplan:</th><td>',htmlspecialchars($row2['subscriptionplan2']),'</td>
                      </tr>
                      <tr>
                      <th>Subscriptionplan Date:</th><td>',htmlspecialchars($row2['subscriptionplandate2']),'</td>
                      </tr>
                      <tr>
                      <th>Monthly Fees:</th><td>',htmlspecialchars($feesmonthly2),'</td>
                      </tr>
                      <tr>
                      <th>Yearly Fees:</th><td>',htmlspecialchars($feesyearly2),'</td>
                      </tr>
                      <tr>
                      <th>Payment Status:</th><td>',htmlspecialchars($row2['paid2']),'</td>
                      </tr>
                      <tr>
                      <th>Expiry Date:</th><td>',htmlspecialchars($row2['expirydate2']),'</td>
                      </tr>
                      <tr>
                      <th>Payment Due Date: </th><td>',htmlspecialchars($row2['paidbydate2']),'</td>
                      </tr>
                      <tr>
                      <th>Email Reminder Status: </th><td>',htmlspecialchars($row2['emailreminder2']),'</td>
                      </tr>
                      <tr>
                      <th>Over Due Status: </th><td>',htmlspecialchars($row2['overdue2']),'</td>
                      </tr>
                       <tr>
                      <th>Activate Status: </th><td>',htmlspecialchars($row2['activate2']),'</td>
                      </tr>';


                      echo '
                      <tr >
                      <th>Subscriptionplan:</th><td>',htmlspecialchars($row2['subscriptionplan3']),'</td>
                      </tr>
                      <tr>
                      <th>Subscriptionplan Joined Date:</th><td>',htmlspecialchars($row2['subscriptionplandate3']),'</td>
                      </tr>
                      <tr>
                      <th>Monthly Fees:</th><td>',htmlspecialchars($feesmonthly3),'</td>
                      </tr>
                      <tr>
                      <th>Yearly Fees:</th><td>',htmlspecialchars($feesyearly3),'</td>
                      </tr>
                      <tr>
                      <th>Payment Status:</th><td>',htmlspecialchars($row2['paid3']),'</td>
                      </tr>
                      <tr>
                      <th>Expiry Date:</th><td>',htmlspecialchars($row2['expirydate3']),'</td>
                      </tr>
                      <tr>
                      <th>Payment Due Date: </th><td>',htmlspecialchars($row2['paidbydate3']),'</td>
                      </tr>
                      <tr>
                      <th>Email Reminder Status: </th><td>',htmlspecialchars($row2['emailreminder3']),'</td>
                      </tr>
                      <tr>
                      <th>Over Due Status: </th><td>',htmlspecialchars($row2['overdue3']),'</td>
                      </tr>
                       <tr>
                      <th>Activate Status: </th><td>',htmlspecialchars($row2['activate3']),'</td>
                      </tr>';






                                 }

                                  echo '</table>';
                                  echo '</table>';
                                  echo '</table>';




                               }
                             }
                         }
                     }

    enter code here

 But it looks like this:

enter image description here

0 个答案:

没有答案