Jump to content

Find item in HTML Table


shogemuk

Recommended Posts

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

Link to comment
Share on other sites

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'

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.