[英]How to combine javascript and php?
A PHP-file is creating a table with one column from a mysql-database. 一个PHP文件正在用mysql数据库中的一列创建一个表。 How could I make a window open which is showing the other columns of the database-row if I click on the row which I want to show?
如果我单击要显示的行,如何打开显示数据库行其他列的窗口?
If you don't understand: 如果您不明白:
-+ I create a table with php, which has 2 columns each row. -+我用php创建一个表,每行有2列。
-+ The number of rows and the content are got from a mysql-database. -+行数和内容均来自mysql数据库。
while ($data= mysqli_fetch_assoc($query))
{
echo "<tr>";
echo "<td style='text-align: center;'>" . $data['number'] . "</td>";
echo "<td>" . $data['name'] . "</td>";
echo "</tr>";
}
Now I want to make a clickable line out of this and this should open a window (the css is not the problem) which is showing other information to this clicked data. 现在,我想以此做一个可点击的行,这应该打开一个窗口(css不是问题),该窗口显示此点击数据的其他信息。
For example I click on the 3rd row, a window should open and show me (for example) the number, the name, the second name, the hobbies and the sex. 例如,我单击第三行,应打开一个窗口,并向我显示(例如)电话号码,姓名,姓氏,爱好和性别。 All this data is stored in the mysql-database.
所有这些数据都存储在mysql数据库中。
while ($data= mysqli_fetch_assoc($query))
{
echo "<tr>";
echo "<td style='text-align: center;'>" . $data['number'] . "</td>"; echo "<td>" . $datensatz['name'] . "</td>"; ?>
<td>
<a href="yourprog.php?number=<? echo $data['number'] ?>&name=<? echo $data['name'] ?>" ></a>
</td><?
echo "</tr>";
}
There's lots of ways you can go about doing this. 您可以通过多种方式进行此操作。 The simplest way here would be to add an onclick listener to the row
最简单的方法是在行中添加onclick侦听器
while ($data= mysqli_fetch_assoc($query))
{
echo "<tr onclick=myfunction() id=". $data['unique_identifier'].">";
echo "<td style='text-align: center;'>" . $data['number'] . "</td>";
echo "<td>" . $datensatz['name'] . "</td>";
echo "</tr>";
}
And myfunction sends an ajax request or you preload the data and just display the data. 并且myfunction发送ajax请求,或者您预加载数据并仅显示数据。 The id serves as either mysql where clause or as a getter in case the data is preloaded
该ID可用作mysql where子句或用作getter(如果数据已预加载)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.