DLookup function or its alternative in PHP

Hi,
I have two tables (A and B)
My web form (insertdata.php) is based on table A.
Table A: id, loading,destination,commission
Table B: id, loading,destination,commission

Objective:
When I select destination on my webform, the next commission filed should show the related commission fetching from table B.
We can use DLookup function in MS Access but can anybody help me to fix this thing please using PHP. As I am new in PHP so please help out me.
Thanks in advance.

Hi Irslan,

Here is a link explaining examples similar to your query. Hope this will help you.
Link - http://www.techonthenet.com/access/functions/domain/dlookup.php

@Elizine - irslan isn’t looking for the DLookup function for MS Access but rather the way to do it in PHP.

@irslan - before I answer your question, I’d like to understand why you are storing the exact same data in two different tables.

Scott

Really thanks for replying.
Input form is based on table A with a little more fields.Everytime the destination is different n hence has to fetch different commission from table b for per trip total. Thats why i want system fetch the commission from table B based on destination.
please assist me accordingly.
thanks

How about posting some schema? All I know is there is destinations and commissions. Those are two different tables. I need more to go on though. What should be going into these tables? What are the fields?

Scott

Table A:
id, date, driver, truck_no, loading, destination, commission, total

Table B:
id, loading, destination,commission

Objective:
in table A drop down box is created on that data saved in Table B for loading and destination.
so while inputting data every time loading and destination will be different. So i will have to calculate incoming per trip. So when I select destination in input form, related commission from Table B should appear in commission field of input form. so that i can calculate the total per trip.
Thanks in advance and please assist accordingly

Sorry, but that still makes no sense to me.

Do you have any code you can post?

Scott

Oh so sorry for not being specific:
Its my input form coding(insertdata.php):

<?php include ( 'header.html');
     include ('selectdriver.php'); 
     include ('selectdestination.php'); 
     include ('selectloading.php'); 

?>
     
<head>
<form name="regisform" action="insertdata.php" method="POST" valign="top" >
        <h3> ADD RECORDS</h3>
        
        &nbsp; &nbsp;Select Date :&nbsp; &nbsp; &nbsp;<input type="date" name="date" value=""  /> 
        &nbsp; &nbsp;Select Driver :&nbsp; <select name="driver" style="width: 163px; align: left">
            <?php 
			foreach ($name as $value):
				echo '<option value="' . $value . '">' . $value . '</option>';
			endforeach;
			?>
			</select><br/>  <br/>  

        &nbsp; &nbsp;Select Truck No:&nbsp; &nbsp;<input type="text"  name="truck_no" value="" style="width: 170px; align: left"  /><br/>  <br/>   
               
      &nbsp; &nbsp;Loading Point: <select name="loading" style="width: 163px; align: left">
            <?php 
			foreach ($loading as $value):
				echo '<option value="' . $value . '">' . $value . '</option>';
			endforeach;
			?>
			</select><br/>  <br/>       
       
       &nbsp; &nbsp;Destination :&nbsp;&nbsp;&nbsp;  &nbsp;   &nbsp;   &nbsp;   &nbsp; <select name="destination" style="width: 163px; align: left">
            <?php 
			foreach ($destination as $value):
				echo '<option value="' . $value . '">' . $value . '</option>';
			endforeach;
			?>
			</select><br/>  <br/>       
             
         &nbsp; &nbsp;1st Drop :&nbsp;&nbsp;  &nbsp;   &nbsp;   &nbsp;   &nbsp; <select name="dropone" style="width: 100px; align: left">
            <option value="KL">KL</option>
            <option value="Shah Alam">Shah Alam</option>
          </select>
         
         &nbsp; &nbsp;2nd Drop :&nbsp;&nbsp;  &nbsp;   &nbsp;   &nbsp;   &nbsp; <select name="droptwo" style="width: 100px; align: left">
            <option value="KL">KL</option>
            <option value="Shah Alam">Shah Alam</option>
            
          </select>
         
         &nbsp; &nbsp;3rd Drop :&nbsp;&nbsp;  &nbsp;   &nbsp;   &nbsp;   &nbsp; <select name="dropthree" style="width: 100px; align: left">
            <option value="KL">KL</option>
            <option value="Shah Alam">Shah Alam</option>
            
          </select>
       
         &nbsp; &nbsp;4th Drop :&nbsp;&nbsp;  &nbsp;   &nbsp;   &nbsp;   &nbsp; <select name="dropfour" style="width: 100px; align: left">
            <option value="KL">KL</option>
            <option value="Shah Alam">Shah Alam</option>
            
          </select>
         &nbsp; &nbsp;5th Drop :&nbsp;&nbsp;  &nbsp;   &nbsp;   &nbsp;   &nbsp; <select name="dropfive" style="width: 100px; align: left">
            <option value="KL">KL</option>
            <option value="Shah Alam">Shah Alam</option>
            
          </select>
         &nbsp; &nbsp;6th Drop :&nbsp;&nbsp;  &nbsp;   &nbsp;   &nbsp;   &nbsp; <select name="dropsix" style="width: 100px; align: left">
            <option value="KL">KL</option>
            <option value="Shah Alam">Shah Alam</option>
          </select>
         
         &nbsp; &nbsp;7th Drop :&nbsp;&nbsp;  &nbsp;   &nbsp;   &nbsp;   &nbsp; <select name="dropseven" style="width: 100px; align: left">
            <option value="KL">KL</option>
            <option value="Shah Alam">Shah Alam</option>
           </select>       <br/>                  <br/>        
              
        &nbsp; &nbsp;DO No :&nbsp;&nbsp;&nbsp;  &nbsp;   &nbsp;   &nbsp;   &nbsp; <input type="number" name="do_no" value="" />  
              <br/> 
        <br/> 
        &nbsp; &nbsp;Select Drops :&nbsp;&nbsp;&nbsp;  &nbsp;  <select name="drops" style="width: 173px; align: left">
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
             <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
            <option value="7">7</option>
          </select>
        
        
              <br/><br/> 
        &nbsp; &nbsp;Commission :&nbsp;&nbsp;&nbsp;  &nbsp;   &nbsp;   &nbsp;   &nbsp; <input type="text" name="commission" value="" /> <br/>    
              <br/> 
                   
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <input type="submit" value="Save" name="Save" /> 
 &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; <input type="submit" value="Delete" name="Delete" /><br/> <br/> <br/> <br/>  
        </form>
  
        <?php
        
    
        if($_SERVER['REQUEST_METHOD']=='POST')
        {
            $erArr = array();             
            require 'connectdb.php';
           
            $id= isset($_POST['id']) ? $_POST['id'] : '';
            $date= $_POST['date'];
            $driver= $_POST['driver']; 
            $truck_no= $_POST['truck_no'];
            $loading= isset($_POST['loading']) ? $_POST['loading'] : '';
            $destination= $_POST['destination'];
            $dropone= isset($_POST['dropone']) ? $_POST['dropone'] : '';
            $droptwo= isset($_POST['droptwo']) ? $_POST['droptwo'] : '';
            $dropthree= isset($_POST['dropthree']) ? $_POST['dropthree'] : '';
            $dropfour= isset($_POST['dropfour']) ? $_POST['dropfour'] : '';
            $dropfive= isset($_POST['dropfive']) ? $_POST['dropfive'] : '';
            $dropsix= isset($_POST['dropsix']) ? $_POST['dropsix'] : '';
            $dropseven= isset($_POST['dropseven']) ? $_POST['dropseven'] : '';
            $do_no= $_POST['do_no'];
            $drops= $_POST['drops'];
            $commission= $_POST['commission'];
            $total= ($drops*10 + $commission);
            if(empty($_POST['driver']))
            {
                $erArr[] ="Mandatory field 'Name' is missing <br/>";
            }
                                   
            foreach ($erArr as $msg) //foreach is used here to process the array
                {
                    echo $msg;
                }   
          $sql = "INSERT INTO "
                  . "main (id, date, driver, truck_no, loading, destination, dropone, droptwo, dropthree, dropfour, dropfive, dropsix, dropseven, do_no, drops, commission, total ) VALUES "
                  . "('$id', '$date', '$driver', '$truck_no', '$loading', '$destination', '$dropone', '$droptwo', '$dropthree','$dropfour','$dropfive','$dropsix','$dropseven','$do_no', '$drops', '$commission', '$total' )"; 

          if(!empty($driver))
             {
                $insertdb = mysqli_query($dbc, $sql);
                echo mysqli_error($dbc);//for trobleshooting eror
                if($insertdb ==1)
                {
                    echo"The Database has been updated successfully"  . "<br/>";
                }
                    else 
                        {
                echo "Please check the error";
                echo mysqli_error($dbc);
                }
              
             } 
        }
        
        ?>

<?Php
include 'connectdb.php';

$count="SELECT id, date, driver, truck_no, loading, destination, dropone,droptwo, dropthree, dropfour, dropfive, dropsix, dropseven, do_no, drops, commission, total from main group by id";

echo "<table border =1  bgcolor=white width=1200px fontsize=10>";
echo "<tr ><th>id</th><th>Date</th><th>Driver</th><th>Truck No.</th><th>Loading</th><th>Destination</th><th>1st Drop</th><th>2nd Drop</th><th>3rd Drop</th><th>4th Drop</th><th>5th Drop</th><th>6th Drop</th><th>7th Drop</th><th>DO No/RM</th><th>Drops</th><th>Commission</th><th>Total</td></tr>";
foreach ($dbc->query($count) as $row) {
echo "<tr ><td>$row[id]</td><td>$row[date]</td><td>$row[driver]</td><td>$row[truck_no]</td><td>$row[loading]</td><td>$row[destination]</td><td>$row[dropone]</td><td>$row[droptwo]</td><td>$row[dropthree]</td><td>$row[dropfour]</td><td>$row[dropfive]</td><td>$row[dropsix]</td><td>$row[dropseven]</td><td>$row[do_no]</td><td>$row[drops]</td><td>$row[commission]</td><td>$row[total]</td></tr>";

}
echo "</table>";
?>

Now i have to put commission manually in commission field of table A (main). I want this commission field fetch the commission from table B (comm) when destination is selected.
Please check it and advice accordingly.
Table A name is: main
Table B name is: comm
Thanks for sparing time for me.

Hmmm…that didn’t help much.

At any rate. What you are asking for is something that would need to be done with AJAX, because you would have to call back to the server, when a selection from one picklist is made, in order to get the selections for the next picklist (if I understand the problem properly, which I fear I don’t).

I’d also like to humbly suggest you learn more about both PHP, HTML, some Javascript, data normalization/ database design and even learn how to use a PHP framework.

Unfortunately, I can’t teach you all those basics in a forum post and you’re going to need those basics to get the job you want to get done, done right. :disappointed_relieved:

Scott

Thanks for ur advice…
Is there any other alternative to complete this logic/calculation please?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.