473,394 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

HTML Tables

Afternoon all.

Just want to know how to create html tables using a for loop.
I need to display 34 html tables, so I figured a for loop will do.
Please show me an example of how to do that.
Also how do I display the results of an sql query onto the html
tables?

Thanks in advance
Aug 18 '08 #1
4 2489
On Aug 18, 7:16*pm, Amie <sthembileng...@gmail.comwrote:
Afternoon all.

Just want to know how to create html tables using a for loop.
I need to display 34 html tables, so I figured a for loop will do.
Please show me an example of how to do that.
for i in range(33):
print "<table border>"
for j in range(numberofrows-1):
print "<tr><td>stuff</td><td>stuff</td><td>stuff</td></tr>"
print "</table>"

Or something like that. You could have for loops for the individual
rows, too.
Aug 18 '08 #2
En Mon, 18 Aug 2008 09:05:30 -0300, Adrian Smith <ad************@yahoo.comescribió:
On Aug 18, 7:16*pm, Amie <sthembileng...@gmail.comwrote:
>Afternoon all.

Just want to know how to create html tables using a for loop.
I need to display 34 html tables, so I figured a for loop will do.
Please show me an example of how to do that.

for i in range(33):
print "<table border>"
for j in range(numberofrows-1):
print "<tr><td>stuff</td><td>stuff</td><td>stuff</td></tr>"
print "</table>"

Or something like that. You could have for loops for the individual
rows, too.
This can be done, but easily becomes unmaintainable.
I'd use a template engine - or at least a library for generating HTML. See this recent thread:
http://groups.google.com/group/comp....0811516b29fcc/

--
Gabriel Genellina

Aug 18 '08 #3
Adrian Smith wrote:
>Just want to know how to create html tables using a for loop.
I need to display 34 html tables, so I figured a for loop will do.
Please show me an example of how to do that.

for i in range(33):
range(33) returns 33 numbers, not 34 (the upper bound is not inclusive).
print "<table border>"
for j in range(numberofrows-1):
This is also off by one.
print "<tr><td>stuff</td><td>stuff</td><td>stuff</td></tr>"
print "</table>"
One extra tip: if you're printing arbitrary strings, you need to encode
them (that is, map &<to HTML entities, and perhaps also deal with
non-ASCII characters). simple ascii-only version:

from cgi import escape

print "<tr><td>", escape("stuff"), </td><td>" # etc

(the above inserts extra spaces around the cell contents, but browsers
don't care about those)

The "escape" function from the cgi module only works for (ascii)
strings; to be able to escape/encode arbitrary data, you'll need a
better escape function, e.g. something like:

import cgi

def escape(text):
if isinstance(text, unicode):
return cgi.escape(text).encode("utf-8")
elif not isinstance(text, str):
text = str(text)
return cgi.escape(text)

The above escapes Unicode strings and encodes them as UTF-8; 8-bit
strings are escaped as is, and other objects are converted to strings
before being escaped.

Tweak as necessary.

</F>

Aug 18 '08 #4
On Aug 19, 6:49*am, Fredrik Lundh <fred...@pythonware.comwrote:
Adrian Smith wrote:
Just want to know how to create html tables using a for loop.
I need to display 34 html tables, so I figured a for loop will do.
Please show me an example of how to do that.
for i in range(33):

range(33) returns 33 numbers, not 34 (the upper bound is not inclusive).
Oops! Thought it went over 0-33, my bad.
Aug 19 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

71
by: tomy_baseo | last post by:
I'm new to HTML and want to learn the basics by learning to code by hand (with the assistance of an HTML editor to eliminate repetitive tasks). Can anyone recommend a good, basic HTML editor that's...
72
by: Mel | last post by:
Are we going backwards ? (please excuse my spelling...) In my opinion an absolute YES ! Take a look at what we are doing ! we create TAGS, things like <H1> etc. and although there are tools...
21
by: BT | last post by:
I inherited a simple page that needs to be Strict HTML and I'm not very familiar with this standard. What I'm trying to do _should be_ pretty simple so I hope someone can point me in the right...
26
by: gswork | last post by:
i hadn't designed a web page from the ground up for about 9 years, then i was asked to do one. I'd dabbled with html and vaigly kept up with some of the developments but other than that i've been...
59
by: phil-news-nospam | last post by:
In followups by Brian O'Connor (ironcorona) to other posts, he repeats the idea that using tables in CSS is not something that should be done because IE doesn't support it. Of course I'm not happy...
136
by: 1001 Webs | last post by:
Every respected Web-authoring Guru says that. This is the era of table-less design, CSS code, XHTML compliant websites. Separate layout from content. There's no reason to use tables any more....
4
by: ink | last post by:
Hi all, I am trying to pull some financial data off of an HTML web page so that I can store it in a Database for Sorting and filtering. I have been thinking about this for some time and trying...
53
by: brave1979 | last post by:
Please check out my javascript library that allows you to create any layout for your web page, nested as deep as you like, adjusting to width and height of a browser window. You just describe it in...
3
by: codemannh | last post by:
I have been trying to figure out the best way to parse some chunks of html code that contain tables. I've been trying to do this with HTML::Parser and HTML::TokeParser and HTML::TokeParser::Simple,...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.