简体   繁体   English

我不想在生成记录时在mysql中显示某些表和某些列

[英]I Don't want to show some tables and some column in mysql while generating my record

Since I have given to administrator to created the form dynamically.when he created form,What I have done is I have created the table for the form dynamically.Every thing is working fine.Now I want to show table and column for report generation .In that I don't want to show (userlogin,place,venue) table for report generation and three columns (user_id,user_common_id,ayear) these three column are common for all the table which I created dynamically . 由于我已经授予管理员动态创建表单的权限。当他创建表单时,我要做的就是动态创建表单的表格。一切正常。现在, 我想显示用于报告生成的表格和列 。因为我不想显示用于生成报告的表(userlogin,place,venue)和三列(user_id,user_common_id,ayear),所以这三列对于我动态创建的所有表都是通用的。 I have given my code what I have done so far. 我已经给出了到目前为止的代码。

Guide me How to write the mysql query for this. 指导我如何为此编写mysql查询。

<?php
    $mysqli = new mysqli("localhost", "root", "", "event");
    $result = $mysqli->query("SHOW TABLES");
    while ( $row = $result->fetch_row() )
    {
    $table = $row[0];
    echo '<h3>',$table,'</h3>';
    $result1 = $mysqli->query("SELECT * FROM $table where ayear='1'");
    if($result1) 
    {
    echo '<table cellpadding="0" cellspacing="0" class="db-table">';
    $column = $mysqli->query("SHOW COLUMNS FROM $table");
    echo '<tr>';
    while($row3 = $column->fetch_row() ) 
    {
    echo '<th>'.$row3[0].'</th>';
    }
    echo '</tr>';
    while($row2 = $result1->fetch_row() ) 
    {
    echo '<tr>';
    foreach($row2 as $key=>$value) {
    echo '<td>',$value,'</td>';
    }
    echo '</tr>';
    }
    echo '</table><br />';
    }
    }
    $mysqli->close();
    ?>

When admin created the forms, here is code for dynamic table and columns.for better projection 当管理员创建表单时,以下是动态表和列的代码。

$query1="create table ".$porg."(id INT NOT NULL AUTO_INCREMENT,".$VALUES.",user_id int(11),user_common_id int(11),ayear varchar(30),PRIMARY KEY (id)) ENGINE = INNODB"; 
      $result=mysql_query($query1);

Put the tables and columns you want to skip in arrays, then use in_array() to test the name before showing it. 将要跳过的表和列放入数组中,然后在显示名称之前使用in_array()测试名称。

Use fetch_assoc rather than fetch_row so you get the column names in the array keys. 使用fetch_assoc而不是fetch_row以便在数组键中获取列名。

<?php
    $skip_tables = array('userlogin', 'place', 'venue');
    $skip_columns = array('user_id', 'user_common_id', 'ayear');
    $mysqli = new mysqli("localhost", "root", "", "event");
    $result = $mysqli->query("SHOW TABLES");
    while ( $row = $result->fetch_row() )
    {
      $table = $row[0];
      if (in_array($table, $skip_tables)) {
        continue;
      }
      echo '<h3>',$table,'</h3>';
      $result1 = $mysqli->query("SELECT * FROM $table where ayear='1'");
      if($result1) 
      {
        echo '<table cellpadding="0" cellspacing="0" class="db-table">';
        $column = $mysqli->query("SHOW COLUMNS FROM $table");
        echo '<tr>';
        while($row3 = $column->fetch_row() ) 
        {
          if (!in_array($row3[0], $skip_columns)) {
            echo '<th>'.$row3[0].'</th>';
          }
        }
        echo '</tr>';
        while($row2 = $result1->fetch_assoc() ) 
        {
          echo '<tr>';
          foreach($row2 as $key=>$value) {
            if (!in_array($key, $skip_columns)) {
              echo '<td>',$value,'</td>';
            }
          }
          echo '</tr>';
        }
        echo '</table><br />';
      }
    }
    $mysqli->close();
    ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想在我的MySQL数据库魅力中添加一个关系,并使用我的魅力创建一些表 - I want to add a relation in my charm for MySQL db and create some tables using my charm 我想将一些图片文件上传到我的服务器并将文件名记录在 mysql 数据库中但不知何故存在问题 - I want to upload some picture files to my server and record the file name in mysql database but somehow there exists a problem MySQL的。 我想替换列中某些值的名称 - mysql. I want to replace the names of a some values in a column 我在mysql数据库中有一些记录。我想使用php以csv文件格式导出每日记录? - I have some record in mysql database .I want to export daily record in csv file format using php? 某些MySQL查询无法生效 - Some MySQL queries don't take effect 我可以在MySQL数据库上将某些表与InnoDB引擎一起使用,并将某些表与MyIsam一起使用吗? - Can i use some tables with InnoDB engine and some with MyIsam on my MySQL database? 无法访问MYSQL中的某些表 - Can't Access Some Tables in MYSQL 我想在此查询中使用MYSQL的一些逻辑 - I want some logic in this query using MYSQL 连接两个MYSQL数据库表,并检查第二个表是否没有记录,然后返回FALSE,如果列具有某些特定值,则也返回FALSE - Join two MYSQL Database tables and check if second table has no record then return FALSE and if a column has some specific value then also FALSE sql:选择一些我不知道全名的列 - sql : select some column which I don't know the entire name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM