函数不显示表

时间:2016-02-02 16:27:39

标签: php mysql css cookies

Soo这给了我错误和idk为什么,表确实存在但仍然不起作用,我做错了什么?

内容确实显示但仍然显示错误而不显示应该

的内容
function content_temp()
{
    if(isset($_GET['action']))
    {
        if($_GET['action'] == 'banlist')
        {
            echo " <div class='positiontable'>
          <table class='MYTABLE'>
          <tr CLASS='MYTABLE'>
                    <th CLASS='MYTABLE' height=40 width=80>User</th>
                    <th CLASS='MYTABLE' height=40 width=80>Time</th>
                    <th CLASS='MYTABLE' height=40 width=180>Reason</th>
                    <th CLASS='MYTABLE' height=40 width=80>Admin</th>
                  </tr>
                  </table>
                  </div> ";

        $query ="SELECT * FROM `Banovi` LIMIT 5"; 
        $row = mysqli_fetch_array($query);
        if($row)
            $name = $row['Ime'];
            $time = $row['Vreme'];
            $reason = $row['Razlog'];
            $admin = $row['Admin'];
            echo " <tr CLASS='MYTABLE'>
                <td CLASS='MYTABLE' height=40 width=80>$name</td>
                <td CLASS='MYTABLE' height=40 width=80>$time</td>
                <td CLASS='MYTABLE' height=40 width=180>$reason</td>
                <td CLASS='MYTABLE' height=40 width=80>$admin</td>
              </tr>";           
        }
    }
}

1 个答案:

答案 0 :(得分:0)

更新2

您可能需要做一些更改:

function content_temp( $con ){
  if(isset($_GET['action'])){
    if($_GET['action'] == 'banlist'){
      echo " <div class='positiontable'>
        <table class='MYTABLE'>
          <thead>
            <tr CLASS='MYTABLE'>
              <th CLASS='MYTABLE' height=40 width=80>User</th>
              <th CLASS='MYTABLE' height=40 width=80>Time</th>
              <th CLASS='MYTABLE' height=40 width=180>Reason</th>
              <th CLASS='MYTABLE' height=40 width=80>Admin</th>
            </tr>
          </thead>
          <tbody>";
          $query ="SELECT * FROM `Banovi` LIMIT 5"; 
          $result = mysqli_query($con,$query);
          while( $row = mysqli_fetch_array($result,MYSQLI_ASSOC) ){

            $name = $row['Ime'];
            $time = $row['Vreme'];
            $reason = $row['Razlog'];
            $admin = $row['Admin'];
            echo "
              <tr CLASS='MYTABLE'>
                <td CLASS='MYTABLE' height=40 width=80>$name</td>
                <td CLASS='MYTABLE' height=40 width=80>$time</td>
                <td CLASS='MYTABLE' height=40 width=180>$reason</td>
                <td CLASS='MYTABLE' height=40 width=80>$admin</td>
              </tr>";
          }?>
        </tbody>
      </table><?php           
    }
  }
}

更新1

content_temp( $con )中,应创建$con并在函数调用时传递:

$con = mysqli_connect("localhost","my_user","my_password","my_database");
content_temp( $con );