使用通配符选择以 XXX 开头的所有列? [英] Selecting all columns that start with XXX using a wildcard?

查看:22
本文介绍了使用通配符选择以 XXX 开头的所有列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有几列名称相似.我如何根据它们开头的单词选择它们?这是一个示例表格布局:

I have several columns in my databases with similar names. How do I select those based on the word they start with? Here's an example table layout:

我尝试使用

$Food = "Vegetable"; 
mysql_query("SELECT `" . $Food . " %` FROM `Foods`");

但它似乎不起作用.

任何帮助将不胜感激:-)

Any help would be appreciated :-)

显然,从我的示例中并不清楚这一点,但我已经知道所有专栏的第一句话.列始终相同,并且不会添加或删除食物种类".PHP 变量仅用于确定我需要的几种集合类型中的哪一种.

推荐答案

没有办法完全按照您的意愿去做.您可以先执行另一个查询以获取所有列名,然后在 PHP 中处理它们并构建第二个查询,但这可能比仅写出您想要的名称更复杂.

There's no way to do exactly what you're trying to. You could do another query first to fetch all the column names, then process them in PHP and build the second query, but that's probably more complex than just writing out the names that you want.

或者这个查询需要动态的原因是什么?表的结构会经常变化吗?

Or is there a reason this query needs to be dynamic? Will the table's structure change often?

这篇关于使用通配符选择以 XXX 开头的所有列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆