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 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c