0

This is code of my Table in PHP. I want to fetch other details from different 2 tables using AJAX in PHP. i am using mysql.I want to show details in table when i select any value from dropdown. Help me please.. I tried so much time but i am not success.

My code is given below.

    <td>
    <?php
    $query = "select * from table_name  order by name ASC ";
    $result= mysql_query($query);
    echo '<select name="id">';
    echo '<option value="">---Select Employee---</option>';
    while ($row=mysql_fetch_array($result))
        {
    ?>
<option value="<?php echo $row['id']; ?>"> <?php echo  ucfirst($row['name']); ?></option>                               
    <?php
         }
         echo "</select>";
    ?>
</td> 
3
  • look at api.jquery.com/jquery.ajax. You will definately find out. It's not so hard as you expect. Commented Jun 5, 2014 at 5:52
  • possible duplicate of dropdown with php and ajax Commented Jun 5, 2014 at 5:52
  • What is condition or relation between two tables? and how do you want to show data from two tables? Commented Jul 15, 2017 at 7:09

1 Answer 1

0

If you want to fetch your selected value from dropdown. then this will help you.

<?php
   $sql= "select * from table_name";
   $res=mysql_query($sql);
   while($row=mysql_fetch_array($res))
   {
?>
     <select name="xyz">
       <option value=""> --- Select ---</option>
<?php
       $sql2="select * from table_name"; 
       $res2=mysql_query($sql2);
       while($row2=mysql_fetch_array($res2))
       {
         if($row2['column_name']==$row['column_name'])
         {
           $selected='selected="selected"';
         } else {
           $selected='';
         }  
?>
          <option value="<?php echo $row2['column_name']; ?>" 
            <?php echo $selected; ?>><?php echo $row2['column_name'] ?>
          </option>
<?php
       }
?>
    </select>
<?php
  }
?>

I think it may help you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.