dpp80346 2010-12-23 01:25
浏览 63
已采纳

使用mysql和php创建一个多步骤的过程

I am working on a script which allows users to create a stepped process.

The steps will consist of sending visitors to urls where they will fill out a form then be directed to the next step the user has created. Each user can create as many steps as they wish and the url for each step will be unique.

I am not sure if I am doing this in the correct/most efficient way so I have a few questions about this. Before I begin here is a simple version of my table structure:

step_id     user_id       step_url                   step_order
  1           1       example.com?step=1              1
  2           2      test.com?step=1                  1
  3           1       example.com?step=3              2

A visitor will be directed to step_url: example.com?step=1 by user_id: 1

On this page there will be a form which contains a hidden field with the value of the step_id like this:

<input type="hidden" name="step_id" value="1">

Once the visitor has filled out this form it will be processed by my script at a url similar to: http://mysite.com/form-process.php

Once the form has been submitted I then need to direct the visitor to the next step my user has created.

I would currently do this using code similar to this:

SELECT step_url FROM table WHERE step_order='$current_step_order'+1

Here are my questions about this:

  1. Is this the best most efficient way to accomplish this? Or is there a better way?

  2. As the step_id column is auto increment...how would I increment the order column by 1 each time a user inserts a new step?

Thanks for taking the time to read this.

Paul

  • 写回答

2条回答 默认 最新

  • duanshang9426 2010-12-23 01:54
    关注

    I think steps in your problem have parent child relationship. so it would be better if you refer steps with whose child is that step. you can use step no as auxiliary field.

    this would be the schema

    step_id     user_id       step_url             parent_id      step_order
      1           1       example.com?step=1        null           1
      2           2      test.com?step=1            null           1
      3           1       example.com?step=3        1              2
    

    and for finding next step you can call

    SELECT step_url FROM table WHERE parent_id='$current_step_id'
    

    you can see more about hierarchical data http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

    Nitin Sharma

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?