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

查看:79
本文介绍了是否选择使用通配符以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天全站免登陆