473,660 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2504
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(numberofr ows-1):
print "<tr><td>st uff</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.comescri bió:
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(numberofr ows-1):
print "<tr><td>st uff</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(numberofr ows-1):
This is also off by one.
print "<tr><td>st uff</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...@python ware.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
6469
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 a step beyond Notepad (not a WYSIWYG tool). Thanks.
72
5395
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 (dreamweaver and the like), they are all at the lowest level of programming (something like assembly as oposed to C++ etc.). These tools create "brain-dead" developers that constantly have to plough through tons of tags to do the simplest thing. ...
21
2883
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 direction. I'm trying to make a table with 2 columns split down the middle - simple enough. In the past, without Strict HTML, I would just specify the width of each 'cell' as 50%, but width isn't allowed in a <td> under Strict HTML. Sometimes I...
26
2463
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 stuck in 1996-7 thinking looking at web pages become more and more sophistocated (and frequently slower to load!) Back then html 3.2 was still the norm and the idea of seperating structure and content, let alone style and structure was only...
59
3648
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 about the fact that IE doesn't support CSS tables. But what can one do about that? And tables of one type or the other are needed in some cases (regardless of whether some people feel it is appropriate or not). So the issue I and considering...
136
4846
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. Everything can be done with CSS. Tables are so 2002ish ... Do you agree with that?
4
2761
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 to find the best way to do it but I am just not experienced enough with this sort of thing to make the best decision, so any advice would be great. The data is on a number of different nested tables with in the HTML, and on a number of different...
53
4113
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 javascript object and that's all. No need to know CSS hacks, no need to clutter your html with tables. http://www.bravelayout.scarabeo.biz/Quickstart
3
2460
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, but I just can't seem to get everything working the way I want. The chunks are from a standard template so there is some structure to the data, but it is not that simple. The problem: There can be bare text before, after or between each table in...
15
5263
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 show - text boxes, input boxes, buttons, hyperlinks ie the usual. The data is not obtained directly from a database.
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8754
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8542
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.