doujie7886 2013-02-13 20:47
浏览 23
已采纳

PHP + MySQL,按类别输出结果

I'm trying to hack the WP plugin 'Contact Form 7' (with the DB extension) to output the results to my liking after the user has submitted the form. I understand why the plugin has to arrange the DB the way it does, but I'm having trouble separating the entries. Usually I would have an index to work with but here I do not.

Here is what my table looks like.

+-----------------+-----------+-----------------+---------------------+-------------+------+
|   submit_time   | form_name |   field_name    |     field_value     | field_order | file |
+-----------------+-----------+-----------------+---------------------+-------------+------+
| 1360190186.3500 | RSVP 2    | text-796        | Mindi               |           0 | NULL |
| 1360190186.3500 | RSVP 2    | text-664        | Smith               |           1 | NULL |
| 1360190186.3500 | RSVP 2    | text-635        | New York            |           2 | NULL |
| 1360190186.3500 | RSVP 2    | menu-359        | A friend of Sarah's |           3 | NULL |
| 1360190186.3500 | RSVP 2    | textarea-518    |                     |           4 | NULL |
| 1360190186.3500 | RSVP 2    | file-29         |                     |           5 | NULL |
| 1360190186.3500 | RSVP 2    | textarea-652    |                     |           6 | NULL |
| 1360190186.3500 | RSVP 2    | Submitted Login | admin               |        9999 | NULL |
| 1360190186.3500 | RSVP 2    | Submitted From  | ::1                 |       10000 | NULL |
| 1360191326.9700 | RSVP 2    | text-796        | Joe                 |           0 | NULL |
| 1360191326.9700 | RSVP 2    | text-664        | Blow                |           1 | NULL |
| 1360191326.9700 | RSVP 2    | text-635        | Somewhere           |           2 | NULL |
| 1360191326.9700 | RSVP 2    | menu-359        | A friend of Bob's   |           3 | NULL |
| 1360191326.9700 | RSVP 2    | textarea-518    |                     |           4 | NULL |
| 1360191326.9700 | RSVP 2    | file-29         |                     |           5 | NULL |
| 1360191326.9700 | RSVP 2    | textarea-652    |                     |           6 | NULL |
| 1360191326.9700 | RSVP 2    | Submitted Login | admin               |        9999 | NULL |
| 1360191326.9700 | RSVP 2    | Submitted From  | ::1                 |       10000 | NULL |
| 1360361333.8800 | RSVP 2    | text-796        | Once                |           0 | NULL |
| 1360361333.8800 | RSVP 2    | text-664        | Again               |           1 | NULL |
| 1360361333.8800 | RSVP 2    | text-635        | Somewhere           |           2 | NULL |
| 1360361333.8800 | RSVP 2    | menu-359        | A friend of Bob's   |           3 | NULL |
| 1360361333.8800 | RSVP 2    | textarea-518    |                     |           4 | NULL |
| 1360361333.8800 | RSVP 2    | file-29         |                     |           5 | NULL |
| 1360361333.8800 | RSVP 2    | textarea-652    |                     |           6 | NULL |
| 1360361333.8800 | RSVP 2    | Submitted Login | admin               |        9999 | NULL |
| 1360361333.8800 | RSVP 2    | Submitted From  | ::1                 |       10000 | NULL |
+-----------------+-----------+-----------------+---------------------+-------------+------+

My PHP is a little rusty so I'm wondering what's the most efficient way to iterate through the only unique field ('submit_time') to isolate the entries?

  • 写回答

2条回答 默认 最新

  • dra8603 2013-02-13 22:43
    关注

    I was able to solve it by creating an array with the unique submit_time fields and then looping through each of those with that as a variable in the query. For those of you interested here is the result.

    $group = mysql_query('SELECT * FROM wp_cf7dbplugin_submits GROUP BY submit_time');
    
    while ($st = mysql_fetch_row($group)) {
        $myarray[] = $st[0];
    }
    
    foreach ($myarray as $value) {
        $query = "SELECT field_value FROM wp_cf7dbplugin_submits WHERE submit_time = ".$value;
        $entry = mysql_query($query);
    
        while ($row = mysql_fetch_row($entry)) {
            if (!empty($row[0])) {
                echo $row[0];
                echo '<br>';
            }
        }
    
        echo '<br><br>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)