简体   繁体   English

使用php动态更改html表单元格内容

[英]Dynamically alter html table cell content using php

I have a php page that shows track listings of classical CD's. 我有一个php页面,显示古典CD的曲目清单。 The table draws data from two very similar but different mysql tables which sometimes leads to (partial) duplication of table rows. 该表从两个非常相似但不同的mysql表中提取数据,有时会导致表行的(部分)重复。

These are the two possibilities (with the number being the track number on the CD): 这是两种可能性(数字是CD上的曲目号):

1 Work title
1 Subwork title


  Work title (possibly altered)
2 Work title

In the first case I want to remove the track number. 在第一种情况下,我想删除曲目号。 In the second case I want to retain the work title in the first line, add the track number of the second line and do nothing with the work title of the second line. 在第二种情况下,我想在第一行中保留作品标题,添加第二行的曲目号,而对第二行的作品标题不执行任何操作。 So the result should look like: 因此结果应如下所示:

  Work title
1 Subwork title


2 Work title (possibly altered)

Can this be accomplished in php or should I look in the direction of javascript or jQuery for a solution? 可以在php中完成此操作,还是应该向javascript或jQuery寻求解决方案? I tried using 我尝试使用

$("div").empty();

but couldn't make it work. 但无法使其正常工作。

All suggestions are welcome. 欢迎所有建议。

If your PHP script is generating your entire table at once, then you can do it in PHP. 如果您的PHP脚本一次生成了整个表,则可以在PHP中完成。 If your PHP script only creates part of the table, sends it to the user, and it is later modified by something like an AJAX call, then you have to do it in Javascript. 如果您的PHP脚本仅创建表的一部分,并将其发送给用户,然后通过诸如AJAX调用的方式对其进行了修改,则您必须使用Javascript进行处理。

The most efficient way would be to process the data on the server (PHP) as it is retrieved from the database. 最有效的方法是在从数据库中检索服务器(PHP)上的数据时对其进行处理。 This way you aren't transferring large data sizes to the client only to have the front-end (javascript) to discard anything of the data this isn't needed. 这样,您就不会仅将前端(javascript)丢弃不需要的任何数据就传输给客户端大数据。 This will create a not so desirable user experience. 这将创建不太理想的用户体验。

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

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