简体   繁体   中英

Dynamically alter html table cell content using php

I have a php page that shows track listings of classical CD's. The table draws data from two very similar but different mysql tables which sometimes leads to (partial) duplication of table rows.

These are the two possibilities (with the number being the track number on the 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? 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. 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.

The most efficient way would be to process the data on the server (PHP) as it is retrieved from the database. 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. This will create a not so desirable user experience.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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