drug95107 2014-12-22 13:57
浏览 12
已采纳

按下按钮时从sql和php获取行内容甚至调用id

I have a table here fetched from SQL with

I have printed a button along with each row of SQL via PHP

output:

--------------------------------------------------------------
|----date-------|   --  button(email)--    |   Sno.          |
------------------------------------------------------------
| 25/12/2014    | --  [some button]    --  |    1.           |
-----------------------------------------------------------
| 29/11/2014    |   --  [some button] --   |    2.           |  
--------------------------------------------------------------
|  15/10/2014   |     --  [some button] -- |.... and so on.  |
--------------------------------------------------------------

So, here is my code for the above table:

$result = mysqli_query($con,"select date_format(cmpstartdatetime, '%d/%m/%Y') as       
campdate,cmpname from Campaigns group by campdate order by campdate DESC");

//echo $result;
$datesappend = "";
if(mysqli_num_rows($result)>0){
echo "<br/><table  id='example1' class='table table-bordered table-striped display'>";
echo "<thead>
        <tr>
            <th># </th>
            <th>Campaign Date</th>
            <th>Email Report</th>
        </tr>
    </thead>
    <tbody>";
//echo "<th><td>Total Mesages</td><td>Delivered</td></th>";
$i=1;
while($row = mysqli_fetch_array($result)) {
    $datesappend.=$row;
    echo "<tr>";

        echo "<td>".$row['campdate']."</td>";
        echo "<td> <input type='button'  text='venkatesh' value='Email' name='testmesssage'                     
   id='testmesssage' class='btn btn-primary'/></td>";
       echo "<td>".$i."</td>";

        $i++;
    echo "</tr>";
}
echo "</tbody></table>";
}
else{
    echo "No campaign was done so far.";
}

}

What I need is every row has a button it has to get the content of that row if a button is pressed need to get date assigned to a variable.

actually the whole functionality is send mails by buttons. That dates related reports have to sent via mails an I have the reports.

I need to fetch data of the same row when the respective button is clicked.

  • 写回答

2条回答 默认 最新

  • dongwanqiang_2017 2014-12-22 14:12
    关注

    try doing somthing like this when you are add the results

    echo "<td id='t".$i."'>".$row['campdate']."</td>";
        echo "<td> <input type='button'  text='venkatesh' value='Email' name='testmesssage' id='testmesssage' class='btn btn-primary' onclick='findresult(".'"t'.$i.'"'.")' /></td>";
       echo "<td>".$i."</td>";
    

    you could even use the onclick event on the table row so that you don't have to click a button just the row.

    as for the javascript try

    <script>
       function findresult(id) {
           alert(document.getElementById(id).innerHTML);
       }
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?