Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading data from table

Status
Not open for further replies.

LookingBeyond99

Programmer
Jul 2, 2001
18
0
0
US
Hi I'm writing a program that allows users to check in, check out, or delete books from a library. all the data is in a html table. I was wondering if there was an easy way of reading data from a table. Or do I have to parse it looking for the <td> and <tr> tags which is teadious. Thanks for any suggestions ahead of time.
 
What do you mean your data is in an html table? Do you mean that it has been loaded into an html table? From where? Normally you display an html form asking for user input, then use POST or GET action to submit the form to another script(many times the same script that just displayed the blank form), and then that script &quot;read&quot;s the data from the form. Is that what you mean?
Hardy Merrill
Mission Critical Linux, Inc.
 
It's not <that> tedious..... is it ;-).... maybe this is barking up the right tree....

-----------------------------------------------------------------
$html = '<HTML>
<HEAD></HEAD>
<BODY>
<TABLE.... you get the idea.../table>
</body>
</html>';

$html =~ /<table.*?>(.*?)</table>/gis;
$table = $1;
while ($table =~ /<tr>(.*?)<\/tr>/gis)
{
$row_num++;
$table_row = $1;
undef @tmp_array;
while ($table_row =~ /<td>(.*?)<\/td>/gis)
{
# got a table definition
push $tmp_array,$1;
}
$table_info_hash{$row_num} = \@tmp_arry;
}
-----------------------------------------------------------------

I have not run that, but hopefully it illustrates using a few regex's to get the contents of an HTML table into a memory structure.

Do I have the refercence to @tmp_array right? <ponder.... I don't have time to check it at the moment..... ponder>

HTH - gotta' go to work.


keep the rudder amid ship and beware the odd typo
 
ok thanks goBoating that helps a lot. And yes the form and data is placed in an html table. Like each row of the table has a checkbox for edit or delete and then the name of the book type thing. I just wanted to know how to parse the table to get the values easily. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top