shogemuk Posted August 16, 2012 Share Posted August 16, 2012 Hi Fellas, I am using a query to pull some information from the database that looks something like this <table> <tr><td>Animal</td><td>Legs</td></tr> <tr><td>Dog</td><td>4</td></tr> <tr><td>Duck</td><td>2</td></tr> <tr><td>Cat</td><td>4</td></tr> </table> 1) Is there a way of styling each <tr> with alternate colours after pulling this information from the database 2) Is there a way of dynamically getting information from a row e.g. if I just want to retrieve the amount of legs a duck has Any help is very much appreciated, Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/267180-find-item-in-html-table/ Share on other sites More sharing options...
xyph Posted August 16, 2012 Share Posted August 16, 2012 Why are you storing an entire HTML table in your database? All of the solutions would be simple if you stored everything properly Table legs - columns: animal, leg_no SELECT leg_no FROM legs WHERE animal = 'duck' Quote Link to comment https://forums.phpfreaks.com/topic/267180-find-item-in-html-table/#findComment-1369910 Share on other sites More sharing options...
shogemuk Posted August 16, 2012 Author Share Posted August 16, 2012 Hi Xyph, The reason it's in the database is that it allows the user to create the information using FCK Editor. They have been doing so for over 5 years now so there is a lot of information and it will be easier to do these thing dynamically. Quote Link to comment https://forums.phpfreaks.com/topic/267180-find-item-in-html-table/#findComment-1369913 Share on other sites More sharing options...
Christian F. Posted August 16, 2012 Share Posted August 16, 2012 I'm afraid you're quite mistaken, at least in your last statement. It will not be easier to do this dynamically, as you'd have to write your own database engine. Instead I strongly recommend to use the database as it was meant to do, and instead get your users to create templates for the code. You can even parse the content the users submits, for the necessary data, before sorting it and putting it into a table properly. Seeing as PHP is especially designed to manipulate string data, and MySQL is not. A miner wouldn't decline using dynamite over a hammer and a chisel, stating that it'd take too long to make the holes for the dynamite. Would he? Quote Link to comment https://forums.phpfreaks.com/topic/267180-find-item-in-html-table/#findComment-1369915 Share on other sites More sharing options...
xyph Posted August 16, 2012 Share Posted August 16, 2012 You might as well store the data in a flat file if that's the case. Regardless, if you're not interested in the correct way to do this, you either need to search for patterns, using regular expressions, or you need to parse the HTML, using something like DOMDocument or a 3rd party parser. Quote Link to comment https://forums.phpfreaks.com/topic/267180-find-item-in-html-table/#findComment-1369918 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.