3

I hope the title wasn't too cryptic, and I am sure there will be other threads like this one but cannot seem to put my finger on the correct terminology.

I have a form that has 3 dropdowns. Let's call them 'sales consultant', sales email & sales team.

What I am looking to do is give a value to 'sales email' & 'sales team' when the sales consultant is chosen from the dropdown 'sales consultant'

The catch, I am using mysql to pull the data for each dropdown. See below:

<div id="sc">
    Sales Consultant
    <input class="" type="text" list="salesconsultant" name="salesconsultant" placeholder="Start typing consultants name" required />
    <datalist id="salesconsultant">
        <?php
            $sql = "SELECT consultant, id FROM salesconsultants";

            $result = $conn->query($sql);

            if (!$result) die($conn->error);

            if($result->num_rows > 0 ) {
                while($row=$result->fetch_assoc()) {
                    echo "<option value=\"".$row["id"]."\">".$row["consultant </option>";
                }

                echo "</datalist>";
            } else {
                echo"record 0";
            }
        ?>
</div>

The other rows I have in the database are 'salesemail', 'id', 'consultant' and 'teamid'.

So when sales consultant 1 is selected it will give the variable $salesemail the value of consultant 1's 'salesemail' and so on.

Is this possible?

2
  • Hi @Connor, your question is a little confusing but I think you are looking for "a way to show a dropdown values based on other dropdown selection". If it is your case take a look in the following thread and please update your question title. stackoverflow.com/questions/23485888/…
    – Nico
    Commented Feb 27, 2019 at 14:14
  • To better understand the case, you could abstract the case showing the selects as simple html and show the relationship between the selected values of one with the rest. It would be easier to help
    – Mario
    Commented Feb 27, 2019 at 14:23

1 Answer 1

1

Just change below line to :

echo '<option value="'.$row["id"].'".','."'.$row["salesemail"].'">'.$row["consultant"].'</option>'; 

In above code you are separating both value by , And you can get these values like this :

        $result = $_POST['yourselectbox'];
        $r1 = explode(',', $result);
        echo "id: ". $r1[0]."<br />";
        echo "email: ". $r1[1]."<br />";

Hope this will work!

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.