doupin8555 2015-02-08 17:16
浏览 13
已采纳

我需要在javascript /服务器端和客户端冲突中使用php变量

I'm new to programming but I know that you need a server-side language to access a database. I'm using php to access my database and display information, but I need to move the information around on the page at the press of a button (.click) with javascript. So the conversion of data from php to javascript is what is giving me trouble.

Basically, I'm building a system where anyone that buys a ticket is entered in a database. My staff go to a page where the ticket buyers get displayed in a table (Expected Attendance) on the webpage as displayed in a picture I added to the jsfiddle (link in the javascript box), and then they check a box (checkbox) if the person actually comes. At the click of a button (Okay), I need all clicked checkboxes to move to the ( Attending) table on the webpage. Code and fiddle below.

PHP

<?php
//Connect to the database
$mysqli = NEW mysqli('localhost:3306','root','password','roster');
//Query the database
$resultSet = $mysqli->query("SELECT * FROM attendant_info");
//Count the returned rows
if($resultSet->num_rows !=0) {
//Turn the results into an associative array
    while($rows = $resultSet->fetch_assoc())
    {
    $ID = $rows['ID'];
    $first_name = $rows['first_name'];
    $last_name = $rows['last_name'];
    $age = $rows['age'];
    $city = $rows['city'];
    $state = $rows['state'];
    $ticket = $rows['ticket'];
    $vip = $rows['vip'];

$entry = "<div id=\"port\"><div id=\"entry\"><!--start of entry-->
<div id=\"ID\"><!--start of ID-->$ID</div><!--end of ID-->
<div id=\"info\"><!--start of info-->
<infowrapper>
<booking><first>First Name:</first><slot1>$first_name</slot1></booking>
<booking><last>Last Name:</last><slot1>$last_name</slot1></booking>
<booking2><age>Age:</age><slot1>$age</slot1></booking2>
<booking4><city>City:</city><slot1>$city</slot1></booking4>
<booking2><state>State:</state><slot1>$state</slot1></booking2>
<booking3><ticket>Ticket#:</ticket><slot1>$ticket</slot1></booking3>
<booking5><vip>VIP:</vip><slot1>$vip</slot1></booking5>
</infowrapper>
<form action=\"\">
Attending<input type=\"checkbox\" name=\"attending\" value=\"attending\">
</form>
</div><!--end of info-->
</div><!--end of entry-->
</div>";

    echo "$entry";
    }   
//Display the results
}else{
    echo "No results.";}
?>

Javascript(Jquery)

$(document).ready(function() {
    $(".bypass").click(function() {
        if ($("#checkbox").click){document.atbox += "entry";
        }
    });
});

Here is a fiddle so you can see the whole thing together. My html is located in the fiddle, StackOverflow was giving me a hard time posting it. http://jsfiddle.net/oy81hrtp/1/

  • 写回答

2条回答 默认 最新

  • dongpu6141 2015-02-08 17:57
    关注

    This may give you some idea.

    Demo:
    http://jsfiddle.net/sfohgrvL/1/


    HTML:

    <div style="border: 1px solid #000; padding:10px">
        <h1>Expected Attendance</h1>
    
        <div id="expected_attendance">
            <p><input type="checkbox" class="my_checkboxes" />Option1</p>
            <p><input type="checkbox" class="my_checkboxes" />Option2</p>
            <p><input type="checkbox" class="my_checkboxes" />Option3</p>
            <p><input type="checkbox" class="my_checkboxes" />Option4</p>
            <p><input type="submit" class="my_submit" /></p>
        </div>
    </div>
    <br></br>
    <div style="border: 1px solid #000; padding:10px">
        <h1>Attendance</h1>
    
        <div id="attendance">
        </div>
    </div>
    

    JS:

    $(function(){
        $(".my_submit").on('click', function(){
            ht = $("#attendance").html();
            $("input:checkbox[class=my_checkboxes]:checked").each(function()
            {
                var th = $(this);
                ht = ht + th.parent().html();
                th.parent().remove();
            });
            $("#attendance").html(ht);
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号