PHP联接 - 提交表单时

时间:2015-06-16 17:09:31

标签: php mysql forms join

所以我对PHP很新。我正在编写一个应用程序来管理客户的工作。基本上我希望用户选择一个客户,然后创建一个工作。创建作业后。客户与工作联系在一起。因此,当用户选择作业时,他看到客户关联。那我该如何链接呢?我应该用什么词来谷歌这样做?

此外,我通过DB的PHP查询获取客户端名称。 我通过他的表格代码来做这件事。

<form action="nc_job.php" method="post" class="form-horizontal" novalidate="novalidate" id="job">
  <div class="tab-content">
    <div id="w4-jt" class="tab-pane active">
      <div class="form-group">
        <label class="col-md-3 control-label">Services</label>
        <div class="col-md-6">

        <?php
          mysql_connect("localhost", "mydb", "mypass") or
            die("Could not connect: " . mysql_error());
          mysql_select_db("itrack_psa");

          $sql = "SELECT v1 FROM services";
          $result = mysql_query($sql);

          echo "<select name='v1' data-plugin-selectTwo class='form-control populate' >";

          while ($row = mysql_fetch_array($result)) {
            echo '<option value="Not Assigned">Not Assigned</option>';
            echo "<option value='" . $row['v1'] . "'>" . $row['v1'] . "</option>";
          }

          echo "</select>";
        ?>

        </div>
      </div>

      <div class="form-group">
        <label class="col-md-3 control-label">Additional Details</label>
        <div class="col-md-6">
          <div name="v2" class="summernote"  data-plugin-summernote 
               data-plugin-options='{ "height": 180, "codemirror": { "theme": "ambiance" } }'>
            Type Here
          </div>
        </div>
      </div>
    </div>

    <!-------------------------------->
    <div id="w4-sc" class="tab-pane">
      <div class="form-group">
        <label class="col-md-3 control-label" for="inputDefault">Job Name</label>
        <div class="col-md-6">
          <input type="text" class="form-control" name="v3">
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-3 control-label">Client</label>
        <div class="col-md-6">

        <?php
          mysql_connect("localhost", "mydb", "mypass") or
            die("Could not connect: " . mysql_error());
          mysql_select_db("itrack_psa");

          $sql = "SELECT `v2`, `v3` FROM client";
          $result = mysql_query($sql);

          echo "<select name='v4' data-plugin-selectTwo class='form-control populate' >";

          while ($row = mysql_fetch_array($result)) {
            echo '<option value="Not Assigned">Not Assigned</option>';
            echo "<option value='" . $row['v2'] . $row['v3'] ."'>" . $row['v2'] . $row['v3'] . "</option>";
          }

          echo "</select>";
        ?>

        </div>
      </div>

      <div class="form-group">
        <label class="col-md-3 control-label">Day</label>
        <div class="col-md-6">
          <div class="input-group">
            <span class="input-group-addon">
              <i class="fa fa-calendar"></i>
            </span>
            <input name="v5" type="text" data-plugin-datepicker class="form-control">
          </div>
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-3 control-label">Start Time</label>
        <div class="col-md-6">
          <div class="input-group">
            <span class="input-group-addon">
              <i class="fa fa-clock-o"></i>
            </span>
            <input name="v6" type="text" data-plugin-timepicker class="form-control">
          </div>
        </div>
      </div>

      <div class="form-group">
        <label class="col-md-3 control-label">End Time</label>
        <div class="col-md-6">
          <div class="input-group">
            <span class="input-group-addon">
              <i class="fa fa-clock-o"></i>
            </span>
            <input name="v7" type="text" data-plugin-timepicker class="form-control">
          </div>
        </div>
      </div>
    </div>

    <!-------------------------------->
    <div class="panel-footer">
      <ul class="pager">
        <li class="previous disabled">
          <a><i class="fa fa-angle-left"></i> Previous</a>
        </li>
        <li type="submit" class="finish hidden pull-right">
          <a  href="javascript:{}" onclick="document.getElementById('job').submit();">Create</a>
        </li>
        <li class="next">
          <a>Next <i class="fa fa-angle-right"></i></a>
        </li>
      </ul>
    </div>
  </form>

1 个答案:

答案 0 :(得分:0)

您需要遵循以下事项才能实现此目标

  1. 创建表格 - 用户,工作,客户

    用户 - UID,姓名,电子邮件...... 客户 - Customer_ID,名称 作业 - JobId,JobDetails,UID,Customer_ID

  2. 因此,当用户创建/发布作业时,将数据插入到具有所选客户ID的作业表中,并且用户ID [假设已登录用户]

  3. 获取结果 - [选择作业]因此,当用户选择作业时,在具有所选作业ID的作业和客户表上创建sql join

  4. 示例

    注意:确保表格字段

    Select j.*,C.cust_name from jobs as j Left join customer as C On j.Customer_ID= C.Customer_ID where j.jobid=selectedjobid