So I am fairly new at PHP. I am writing an app to manage customers with jobs. Basically I want the user to choose a customer and then create a job. Once the job is created. The customer becomes linked with the job. Therefore when the user selects a job he see the customer associated. So how do I link them? What term should I google to do this?
Also I am getting the client name thru a PHP query from DB. I am doing this through a from, his the code of the form.
<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>
You need following things to achieve this
Create tables - User,Jobs,Customers
User - UID,Name,Email... Customer - Customer_ID,Name Job - JobId,JobDetails,UID,Customer_ID
So when user will create/post job insert data into job table with selected customer id, and user id[ assuming logged in user]
Fetch Result - [Select job] So when User select Job ,create sql join on jobs and customer table with selected job id
Example
Note : Make sure table fields
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