Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

php - update data in the div

I have a problem with updating the data I display from my db. Initially, when the page opens I display the date corresponding to the current date but then the user can change the date by entering it in a text box and when he clicks update all the data displayed should be deleted and the data corresponding to the new date should be displayed. Right now I have a javascript function which deleted all the data in the div when the button is clicked. The div holds the data I want to change. But I don't know how to add new data into the div. I tried to add php code to look up the database for the data in the javascript function but I don't know how to add it to the text box.

function changedate()
{
    document.getElementById("label1").innerText=document.getElementById("datepicker").valu e;
    document.getElementById("selecteddate").innerText=document.getElementById("datepicker"  ).value;
    document.getElementById("teammembers").innerHTML = "";//empties the div(teammembers)

    <?php
    $con=mysqli_connect("localhost","*****","*****","*****");
    $result = mysqli_query($con,"SELECT * FROM users");
    while($row = mysqli_fetch_array($result))
    {
        if(trim($user_data['email'])!=trim($row['email']))
        {
            $email_users = $row['email'];
            //I want to first show this email but I don't know how to add it to the div.
        }
    }
    ?>
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You want to output a literal JS statement with whatever you get back from php, basically:

document.getElementById("teammembers").innerHTML = // notice no erasing, we just
                                                   // overwrite it directly with the result

"<?php
  $con=mysqli_connect("localhost","*****","*****","*****");
  $result = mysqli_query($con,"SELECT * FROM users");
  while($row = mysqli_fetch_array($result))
  {
      if(trim($user_data['email'])!=trim($row['email']))
      {
          $email_users = $row['email'];
          //I want to first show this email but I don't know how to add it to the div.
          // so just show it!
          echo $email_users;     // think about this for a second though
                                 // what are you trying to achieve?
      }
  }
  ?>"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...