从 SHOW COLUMNS mysql 中排除某些列
我有这个查询:SHOW COLUMNS FROM mash
,它在我的 while 循环中运行良好,用于构建由表列名称组成的选择元素。但在我的表中,我在选择元素中有“id”和“tstamp”,我不希望这些列出现,是否可以排除这些列?
echo "<form action='".$_SERVER['PHP_SELF']."' method='get'>";
connectDB();
$result = mysql_query("SHOW COLUMNS FROM mash") or die(mysql_error());
echo '<select name="column" class="column">';
while ($row = mysql_fetch_array($result)) {
echo "<option value='".$row[0]."'>".ucwords($row[0])."</option>";
}
closeConn();
echo '</select>';
echo "</form>";
I have this query: SHOW COLUMNS FROM mash
which works fine in my while loop for building a select element made from table column names. But in my table i have "id" and "tstamp" which i dont want in the select element, is this possible to exclude these columns?
echo "<form action='".$_SERVER['PHP_SELF']."' method='get'>";
connectDB();
$result = mysql_query("SHOW COLUMNS FROM mash") or die(mysql_error());
echo '<select name="column" class="column">';
while ($row = mysql_fetch_array($result)) {
echo "<option value='".$row[0]."'>".ucwords($row[0])."</option>";
}
closeConn();
echo '</select>';
echo "</form>";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
PHP方式:
当获取这些字段时,在 while 循环中使用
continue
,例如this:这将跳过 id 和 tstamp 字段并处理所有其他字段。
continue
用于循环结构中,以跳过当前循环迭代的其余部分,并在条件评估时继续执行,然后在下一次迭代开始时继续执行。MySQL 方式:
删除查询中的这些字段,如下所示:
PHP Way:
Use a
continue
in the while loop, when those fields are fetched, like this:This will just skip the
id
andtstamp
fields and process all others.continue
is used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration.MySQL Way:
Remove those fields in the query like this:
是的,这是可能的。不要使用
SHOW COLUMNS
使用INFORMATION_SCHEMA
。INFORMATION_SCHEMA
是从关系数据库中提取元数据的 ANSI 方法。在 MySQL 中,您可以使用:信息模式的优点是符合 SQLANSI。您可以在MySQL、PostgreSQL、SQLServer和其他关系数据库中使用它。
Yes, it's possible. Instead of using
SHOW COLUMNS
useINFORMATION_SCHEMA
.INFORMATION_SCHEMA
is the ANSI way of extracting metadata from a relational database. In MySQL you can use:Information Schema has the advantage that is SQLANSI compliant. You can use it in MySQL, PostgreSQL, SQLServer and other relational databases.
您可以使用 LIKE 运算符。
You can use LIKE operator.
要仅查看一个字段的
SHOW FULL COLUMNS from tablename
中显示的“排序规则”列,请执行以下操作:将
fieldname
拖放到where
中>,如果您想查看该列的所有字段名称。要查看从
SHOW FULL COLUMNS
显示的所有可能的列名称,以便您可以选择所需的内容:To see just the "Collation" column that shows up in
SHOW FULL COLUMNS from tablename
for just one field, it's:Ddrop the
fieldname
in thewhere
, if you want to see that column for all field names.To see all possible column names that show up from
SHOW FULL COLUMNS
so that you can select what you want: