dt2002 2018-10-31 07:16
浏览 72

获取特定行的单元格数据

Hey guys I have this code that gets data from my database and posts it to an html table. I want to send a particular row or cell data corresponding to the button,once the button is clicked, to a paragraph element I used this

console.log(this.childNodes[0].innerHTML); // column 1 in row1  

but it doesn't work Here is my code

 <?php
    if(isset($_POST['searchbox'])){    
        $bloodonation =$_POST['searchbox'];
        $multiple= explode(',',$bloodonation);
        $var1 = $multiple[0]; // firstname                                                                                                   
        $var2 = $multiple[1]; // fathername
        $var3 = $multiple[2]; // lastname                /*bloodtype.blood_type='$var4' AND bodytype.bodytype='$var5' AND */
        $_SESSION["firstname"] = $var1;
        $_SESSION["fathername"] = $var2;    
        $_SESSION["lastname"] = $var3;  
        if(!empty($bloodonation)){
            //$myfile = fopen("file.txt", "w");
            //file_put_contents('file.txt',$bloodonation);
            //fclose($myfile);
            $bloodquery ="SELECT personprofile.firstname,personprofile.fathername,personprofile.lastname,bloodtype.blood_type,bodytype.bodytype,personprofile.bloodoner,personprofile.organdoner
                        FROM personprofile,bloodtype,bodytype
                        WHERE   personprofile.bloodtype= bloodtype.id AND 
                                personprofile.hascancer ='No' AND personprofile.chronicdisease= 'No' AND personprofile.autoimmunedisease= 'No' AND
                                personprofile.bodytype= bodytype.id";

            //$sql = "SELECT `firstname`, `fathername`, `lastname` FROM `personprofile` WHERE chronicdisease=\"No\" AND hascancer=\"No\" AND autoimmunedisease=\"No\"";
            $bloodqr=mysqli_query($link,$bloodquery);

            echo "<table>";
            echo "<tr><th>Firstname</th><th>Fathername</th><th>Lastname</th><th>Blood type</th><th>Body type</th></tr> ";
            while($row=mysqli_fetch_assoc($bloodqr)){
                echo"<tr><td>";
                echo $row['firstname'];
                echo "</td><td>";
                echo $row['fathername'];
                echo "</td><td>";
                echo $row['lastname'];
                echo "</td><td>";
                echo $row['blood_type'];
                echo "</td><td>";
                echo $row['bodytype'];
                echo "</td><td>";?><html><button onclick="outputdata()">Send Email</button></html> <?php 
                echo"</td></tr>";

            }
        } 
    } ?>
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var paragraphdata = document.getElementById("demo");

function outputdata() {
        console.log(this.childNodes[0].innerHTML); // col1
        console.log(this.childNodes[1].innerHTML); // col2
        paragraphdata.innerHTML = "Geolocation is not supported by this browser.";
    }
</script>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dongxixiu9134 2018-10-31 09:14
    关注

    You can try to use like this method. Firstly you should set an unique id in the tr tag. And you can get data of the td tag with the tr tag id.

    echo '<tr id="'.$unique_id.'">';
    
    $("button").click(function(){
        console.log($(this).closest('tr').index()); // Get the value of tr tag id.
    }
    
    • And also you can try to use this link
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看