簡體   English   中英

是否可以在同一PHP文件中傳遞數據?

[英]Is it possible to passing data in same PHP file?

我有一個按鈕(有人創建了它,我需要編輯),該按鈕保存到$elisting中的$elisting中。 該按鈕將轉到名為edit() javascript函數。 $elisting代碼如下:

$elisting ="";

    $queryf = "select employee.id as myid,jobtitle,info,locid,deptid,gender,dob,emid,employee$cid.name,username,dept,datejoin,location.name as loc from  employee

        left join location on location$cid.id = employee.locid 

        inner join department on department.id = employee.deptid order by username

    ";

    $resultf = pg_query($queryf); 

    $numrows = pg_numrows($resultf);

    while ($rowf = pg_fetch_array($resultf)) {

        $ct=$ct+1;

        $myid = $rowf[myid];

        $uname = $rowf[username];

        $loc1 = $rowf[loc];

        $dept = $rowf[dept];

        $date = $rowf[datejoin];

        $name = $rowf[name];

        $emid = $rowf[emid];

        $dob = $rowf[dob];

        $gender = $rowf[gender];

        $job = $rowf[jobtitle];

        $info = $rowf[info];

        $datejoin = $rowf[datejoin];

        $locid = $rowf[locid];

        $deptid = $rowf[deptid];

        $newbal = $rowf[newbal];

        $templatelist = "";

        $tempcn = 0;

        $querytemp = "select tid,ltype from leaveatemplate$cid where username='$uname' order by tid desc";

        $resulttemp = pg_query($querytemp); 

        while ($rowtemp = pg_fetch_array($resulttemp)) {

            $tempcn = $tempcn +1;

            $tid = $rowtemp[tid];

            $ltype = $rowtemp[ltype];

            if($tempcn=="1")

                $templatelist = "$ltype|$tid";

            else

                $templatelist = $templatelist.","."$ltype|$tid";

        }

$elisting=$elisting."<tr><td align=\"center\">$uname</td><td align=\"center\">$loc1</td><td align=\"center\">$dept</td>
        <td align=\"center\">$date</td>
        <td align=\"center\"><a><button class=\"btn btn-mini\"data-toggle=\"modal\"href=\"#long\"
        onClick=\"javascript:edit('$name','$uname','$emid','$dob','$gender','$job','$info','$datejoin','$locid','$deptid','$myid','$templatelist');\"><i class=\"icon-pencil\"></i></a>

這是javascript edit()代碼:

function edit(a,b,c,d,e,f,g,h,i,j,k,l){
        document.getElementById("frm").id.value=k;
      document.getElementById("frm").name.value=a;
        document.getElementById("frm").username.value=b;
        document.getElementById("frm").emid.value=c;
      document.getElementById("frm").dob.value=d;
        setCheckedValue(document.forms['frm'].elements['gender'],e);
        document.getElementById("frm").job.value=f;
        document.getElementById("frm").info.value=g;
        document.getElementById("frm").datejoin.value=h;
        document.getElementById('locid').value=i;
        document.getElementById('deptid').value=m;

      var params = b;
      window.location.href="http://192.168.1.5/eleave/employee.php?lapplicant=" + params;

        var myTemp = l;
        var mySplitResult = myTemp.split(",");
        for(i = 0; i < mySplitResult.length; i++){
            cval = mySplitResult[i];
            myval = cval.split("|");
            val1 = myval[0];
            val2 = myval[1];
            document.getElementById('temp'+val1).value= val2;
        }

由於我無法嘗試通過多種方法在edit()獲取b ,因此我需要找到在$elisting獲取$ uname並將其發送至以下$llisting所在的同一PHP文件(employee.php)中的方法。 :

$llisting ="";

    $ct=0;

    //leave code
    $ccompassionate = "3";
    $cemergency = "4";
    $cmaternity = "5";
    $cmedical = "6";
    $cannual = "2";

    //leave value
    $compassionate = 2;
    $emergency = 5;
    $maternity = 60;
    $medical = 20;

    $lapplicant = $_POST['lapplicant'];

    $querye = "select leavetype.id, leavetype.ltype, leaves.leave from leavetype,leaves where username='".$_SESSION["username"]."'";

        $resulte = pg_query($querye); 

        while ($rowe = pg_fetch_array($resulte)) {

            $ct=$ct+1;

            $lid = $rowe[id];

            $ltype = $rowe[ltype];

            $leave = $rowe[leave];  

        if ($lid == $ccompassionate) {
            $compassionate_query = pg_query("select ltotal from leave where lapplicant='".$lapplicant."' and ltype='".$ccompassionate."'");
            if (count($compassionate_query) > 0) {
                foreach ($compassionate_query as $data) {
                    $total_compassionate = $total_compassionate + $data['total'];
                    $value = $compassionate - $total_compassionate;
                }

            } else {
                $value = $compassionate;
            }
$llisting=$llisting."<tr><td align=\"center\">$ct</td><td>$ltype</td><td><input type='text' value='$lapplicant'></td><td align=\"center\">";

        $llisting=$llisting."<select name=\"temp$lid\" id=\"temp$lid\" class=\"span12\"><option value=\"0\"> - </option> $tlisting</select>";

        $llisting=$llisting."</td></tr>\n";

任何人都有想法在$elisting獲得$uname並發送給$llisting嗎?

而且, '$name','$uname','$emid','$dob','$gender','$job','$info','$datejoin','$locid','$deptid','$myid','$templatelist'$elisting變化到a,b,c,d,e,f,g,h,i,j,k,ledit()我是Javascript中的新功能,所以我不知道該如何更改?

謝謝你的幫助..

在此處輸入圖片說明

這是href="#long"調用的代碼:

<div id="long" class="modal hide fade" tabindex="-1" data-replace="true" data-width="760">
    <div class="modal-header"><h3>Employee Profile</h3></div>
    <div class="modal-body">
        <form class="form-horizontal" method="Post" name="frm" id="frm">

調用html頁面的代碼:

if($msg!="") $alert= "<div class=\"alert\"><i class=\"icon-info-sign\"></i> $msg</div><p>&nbsp;</p>";

    $source2 = file_get_contents('http://'.$_SESSION["url"].'/cgi-bin/vo/'.$_SESSION["sessid"].'.interface.designer.vo?file=eleave/employee.htm');

    $html2 = str_replace("[templateurl]",$templateurl,$source2);

    $html2 = str_replace("[alert]",$alert ,$html2);

    $html2 = str_replace("[elisting]",$elisting ,$html2);

    $html2 = str_replace("[ulisting]",$ulisting ,$html2);

    $html2 = str_replace("[locationlisting]",$locationlisting ,$html2);

    $html2 = str_replace("[deptlisting]",$deptlisting ,$html2);

    $html2 = str_replace("[llisting]",$llisting ,$html2);

    $html2 = str_replace("[wfid]","sid=$sid" ,$html2);

    echo $html2;

請先嘗試基本內容,我對此沒有任何問題。

在JS中:

<script>
    function TestTriggered(name){
        alert("the function triggered!");
        alert("My name is: " + name);
    }
</script>

在HTML部分

<input type="button" name="myButton" onClick="javascript:TestTriggered('John');" value="Please click"/>

請先嘗試一下,看看它如何工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM