473,779 Members | 2,089 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 2512
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
6506
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
5444
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
2900
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
2484
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
3669
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
4894
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
2766
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
4140
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
2471
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
5276
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
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10139
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
10075
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,...
0
9931
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7485
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
6727
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();...
1
4037
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
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
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.