doucheyi1347 2009-10-06 17:39
浏览 19
已采纳

在mysql的单个列中创建包含结果的视图

I would like to create a view that has a single column. If my two tables looked like the following:

Table 1: ID | Name 1 | Joe

Table 2: ID | Address 1 | 123 BlueBerry St.

The view would look like: View: newcolumn | Joe 123 Blueberry St.

The reason I do this is because I have an autocomplete text box that searchs a single column with the following php / jquery code:

$query = $db->query("SELECT value FROM countries WHERE value LIKE '$queryString%' LIMIT 10");
if($query) {
    while ($result = $query ->fetch_object()) {
    echo '<li onClick="fill(\''.$result->value.'\');">'.$result->value.'</li>';
     }
     }

If there is a better way than putting all values into a single column for this solution, please let me know as well.

  • 写回答

1条回答 默认 最新

  • duanli3277 2009-10-06 17:47
    关注

    You view wouldn't be able to be searched over anyways. Do a table join and LIKE query on all the columns you want to match.

    Like

    SELECT value FROM table1 INNER JOIN table2 USING (id) WHERE table1.col1 LIKE '%:query%' AND table2.col1 LIKE '%:query%' LIMIT 10
    

    And PLEASE don't use PHP variables in your query string. Use PDO instead

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路