gpt4 book ai didi

javascript - 如何使用 php 从 html 行(在表中)获取数据

转载 作者:行者123 更新时间:2023-11-30 21:55:35 25 4
gpt4 key购买 nike

我试图在有人点击我的动态表时获取信息,这样我就可以逐列阅读并提取数据,然后将其显示在文本框中。不知道该怎么做,因为我是这种语言的新手,希望您能提供帮助。我现在正在做的是从我的数据库中提取数据并用它创建动态表。我已经尝试了几件事,但都没有奏效,所以我不会在这里粘贴所有失败的尝试。这是我的代码(因为很多人对它是 mysql 有疑问,所以我将它更新为 Mysqli_:

    if (($result)||(mysqli_errno == 0))
{
echo "<table cellspacing='0' cellpadding='0' border='0' width='126%'>
<tr>
<td>
</table>
<div style='width:450; height:350px; overflow:auto;'>
<table cellspacing='0' cellpadding='1' border='1' width='380px'>
<tr style='color:white;background-colorgrey'>";
if (mysqli_num_rows($result)>0)
{
//loop thru the field names to print the correct headers
$i = 0;
while ($i < mysqli_num_fields($result))
{
$fetch = mysqli_fetch_field_direct($result, $i);
echo "<th>". $fetch->name . "</th>";
$i++;
}
//display the data
while ($rows = mysqli_fetch_assoc($result))
{
echo "<tr>";
foreach ($rows as $data)
{
echo "<td align='center' width='400px'>". $data . "</td>";
}
echo"</tr>";
}
}else{
echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";
}
echo "</table></div>";

最佳答案

对于任何对答案感兴趣的人,我已经弄清楚了(变量“id”存储列“0”中的元素,但您可以更改 0 以获得不同的列):

        <table cellspacing='0' cellpadding='0' border='0' width='126%'>
<tr>
<td>
</table>
<div style='width:450; height:350px; overflow:auto;'>
<table style="display: table-row" class='prueba' cellspacing='0' cellpadding='1' border='1' width='380px'>
<tbody>
<tr style='color:white;background-colorgrey'>

<?php

///******///
///CONECTION AND QUERY INFO WOULD GO HERE///
///******///

if (($result)||(mysqli_errno == 0))
{

if (mysqli_num_rows($result)>0)
{
//loop thru the field names to print the correct headers
$i = 0;
echo "<th><a>Check</a></th>";
while ($i < mysqli_num_fields($result))
{
$fetch = mysqli_fetch_field_direct($result, $i);
echo "<th><a>". $fetch->name . "</a></th>";
$i++;
}
//display the data
while ($rows = mysqli_fetch_assoc($result))
{
echo "<tr onClick='Content(this)'>";
foreach ($rows as $data)
{
echo "<td align='center' width='400px'><a>". $data . "</a></td>";
}
echo"</tr>";
}
}/*else{
echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";
}*/

}else{
echo "'Error in running query :'. mysqli_error()";
}

//echo "<style>";

/*echo "</tr></table></td></tr><tr><td>
<table min-width='400px' cellspacing='0' cellpadding='1' border='1'>";*/

echo "</table></div>";
echo "<script>
function Content(elem){
elem.style.backgroundColor = 'red';

var id = $(elem).find('td:eq(0)').text();
alert(id);}
</script>";
?>
</p>

关于javascript - 如何使用 php 从 html 行(在表中)获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45300788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com