我不想在生成记录时在mysql中显示某些表和某些列 [英] I Don't want to show some tables and some column in mysql while generating my record
问题描述
自从我已经赋予管理员动态创建表单的权限.当他创建表单时,我要做的就是动态创建表单的表格.一切正常.现在我想显示表格以及用于生成报告的列.因为我不想显示用于生成报告的(用户登录,位置,地点)表和三列(用户ID,用户_共同ID,年) 这三列对于我动态创建的所有表都是通用的.我已经给出了我到目前为止的代码.
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 . I have given my code what I have done so far.
指导我如何为此编写mysql查询.
Guide me How to write the mysql query for this.
<?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);
推荐答案
将要跳过的表和列放入数组中,然后使用in_array()
在显示名称之前对其进行测试.
Put the tables and columns you want to skip in arrays, then use in_array()
to test the name before showing it.
使用fetch_assoc
而不是fetch_row
,以便在数组键中获得列名.
Use fetch_assoc
rather than fetch_row
so you get the column names in the array keys.
<?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();
?>
这篇关于我不想在生成记录时在mysql中显示某些表和某些列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!