简体   繁体   English

在表格单元格中隐藏/显示更多文本按钮

[英]Hide/show more text button within table cell

I currently have a html table that is populated using a PHP script. 我目前有一个使用PHP脚本填充的html表。 The script loops through a table in my database and outputs the values of 2 fields into two different cells in the table, over and over... The two different values are a review of a university hall, and the name of the person who left the review. 脚本循环遍历数据库中的一个表,并将2个字段的值一遍又一遍地输出到表中的两个不同的单元格中。这两个不同的值是对大学礼堂的评论以及离开者的姓名评价。

Some reviews can be very long and therefore need to be shortened, using a more/less button. 有些评论可能会很长,因此需要使用“更多/更少”按钮来缩短。 I am unsure how to create this button and get it to appear in every cell of the table (so each review can be expanded). 我不确定如何创建此按钮并将其显示在表格的每个单元格中(因此可以扩展每个评论)。

I'm aware I've not explained this very well, but if anybody knows of a way to achieve this I would be very grateful! 我知道我对此的解释不是很好,但是如果有人知道实现这一目标的方法,我将不胜感激!

EDIT: 编辑:

Sorry I should have put my code in here. 抱歉,我应该将代码放在这里。

Below is the HTML code for the table and the PHP code: 以下是表格的HTML代码和PHP代码:

<tr>
<td><table class="flat-table flat-table-1" width="100%">
<tr>
</tr>

<tr style="background-color:#FFF;">
<td class="table-head">Name</td>
<td class="table-head">Rating</td>
</tr>

<?php
//run a query to find all the fields in the hall table that belong to the specific     university, using the id in the url ($current_id)
if ($r = $db->prepare("SELECT * FROM reviews WHERE hall_id = :current_id")) { 
  $r->bindParam(':current_id', $current_id);
  $r->execute(); // Execute the prepared query.

//search table for all fields and save them in $hall
$reviewtemp = $r->fetchAll();
foreach( $reviewtemp as $review) {

//loop and output hall names below
?>
<tr>
<td><? echo $review['name'];?></td>
<td><? echo $review['review']; }}?></td>
</tr>
</table>
</td>
</tr>
</table>

The more/less button needs to appear at the bottom of this 'td' - 更多/更少按钮需要显示在此“ td”的底部-

<td><? echo $review['review']; }}?></td>

why not just output a javascript link that would hide/show additional content? 为什么不只输出将隐藏/显示其他内容的JavaScript链接?

show more with javascript 用javascript显示更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM