Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 for web-developers: how to make paragraph breaks

Author  Topic 

token
Posting Yak Master

133 Posts

Posted - 2005-11-07 : 19:05:03
in my on-going novice quest to make my own e-commerce store, I have stumbled upon yet another mundane problem (which others might have faced as well?).

Quite simply, I have a table named Products that stores info on products for sale. Products will have a model name, price, etc. But the tricky part comes to entering specifications. I want my webpage to display the specifications as bullet-point lists. For example:

· AMD 64bit Processor
· 1024MB RAM

You get the idea right? So the prestentation of the data as bullet-points is handled by CSS/HTML. But CSS/HTML will only format each new paragraph as a bullet-pointed sentence. So the text that is stored in the "Description" cell in my database needs to indicate where the paragraph breaks take place so that CSS/HTML can give it a bullet-point. Is there anyway to do this at all?

I'll be amazed if anyone read this post to the end! Thanks in advance for your time and effort.

Token.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-11-07 : 20:42:19
quote:
But CSS/HTML will only format each new paragraph as a bullet-pointed sentence.
That is astonishingly untrue. Not being critical here, but it's just not correct. What you want to do is use the HTML list:
  • AMD 64 bit Processor
  • 1024 MB RAM
You can also create a numbered or lettered list with essentially the same markup:
  1. AMD 64 bit Processor
  2. 1024 MB RAM
  1. AMD 64 bit Processor
  2. 1024 MB RAM
You can also style your lists with CSS so that they appear any way you like, for examples go here:

http://www.alistapart.com/articles/taminglists/

They're just much easier to handle and a lot more flexible. Lately I've been using lists for menus, including drop-downs, and some other things. A List Apart has so many articles on how to do this it actually gets boring to read them all.

If you view the source of this web page you'll see the actual HTML markup you'd need to generate. It's pretty simple really.
Go to Top of Page

token
Posting Yak Master

133 Posts

Posted - 2005-11-08 : 06:47:07
Right, I understand the HTML mark-up for making a list... but the information in my database for specifications is all in one cell named "Specifications". So my information looks like this in the table cell:

AMD 64Bit Processor for devastating speed, 1024MB RAM, 80GB Hard Disk for all your music, etc, etc.

So when I take that information and place it on my webpage, it all displays as one big sentence. I would like to split the information up where the commas are and bullet-point the sentence.

Any ideas on how to achieve this? The only other alternative I have found is to get rid of the "Specifications" cell and instead create many cells like Feature1, Feature2... FeatureN. So then I place each Feature cell on the webpage and apply a HTML list markup to it. This is a bit of a tedious way for me to enter in product specifications. It is easier for me to copy+paste all the product specifications into a "Specifications" cell and then use HTML to make a list out of it.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-11-08 : 07:29:08
Here's a quick and dirty bit of SQL to generate an HTML fragment:

SELECT '<li>' + replace(Specifications, ',', '</li><li>') + '</li>' AS Features FROM myTable WHERE product='Whiz Bang AMD Computer'

Here's some ASP code:

Response.Write "<ul>" & rs("Features") & "</ul>"

As far as table structure goes, you're better off with a separate table for the specs/features, and storing one feature per row for each item. Example:

CREATE TABLE Features (productID int not null, feature varchar(25) not null, displayOrder smallint not null Default(0))
INSERT Features(productsID, feature, displayOrder) VALUES(1234, 'AMD 64 Bit Processor', 1)
INSERT Features(productsID, feature, displayOrder) VALUES(1234, '1024 MB RAM', 2)
INSERT Features(productsID, feature, displayOrder) VALUES(1234, '80 GB Hard Disk', 3)


You then have a simpler SELECT statement for your web page, and adding or removing features is easier, you just insert or delete the appropriate rows. You can also make mass updates easier. For instance, all computers with 80 GB drives get 100 GB drive upgrades:

UPDATE Features SET Feature='100 GB Hard Disk' WHERE Feature='80 GB Hard Disk'
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-11-08 : 08:30:58
What tecnology are you using? ASP? ASP.NET? PHP?

It is very, very easy to do your formatting at the presentation layer and not within sql.

Sample data how also help -- it is in the format that Rob indicates (1 description line per row in your table) or is it all stored in 1 row and needs to be broken out?

How about providing us with some specfics.
Go to Top of Page

token
Posting Yak Master

133 Posts

Posted - 2005-11-08 : 09:05:24
I'm using ColdFusion.

My Products table looks like this:

PRODUCT ID | MAKE ID | PRODNAME | IMAGEURL | SPECIFICATIONS
=====================================================================
1                   1            4200WMLi    img.jpg        AMD 64bit, 512MB RAM, 80GB HDD


MAKE ID is related to another table called MAKES which contains different names for different manufacturers.

On my webpage, everything is displayed nicely until I get to the specification part. It displays everything as one big sentence. I just need it to place each new specification feature (e.g. 80GB HDD) on a new line with a bullet-point. Like this:

· 80GB HDD

So I was thinking that in my Specifications cell that I should place some kind of HTML code like </p>. Or follow robvolk's kind suggestions.


Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-11-08 : 09:52:39
>>Or follow robvolk's kind suggestions.

Yes. Normalize your database; store 1 description per row.
Go to Top of Page

token
Posting Yak Master

133 Posts

Posted - 2005-11-08 : 15:20:16
quote:
As far as table structure goes, you're better off with a separate table for the specs/features, and storing one feature per row for each item. Example:

CREATE TABLE Features (productID int not null, feature varchar(25) not null, displayOrder smallint not null Default(0))
INSERT Features(productsID, feature, displayOrder) VALUES(1234, 'AMD 64 Bit Processor', 1)
INSERT Features(productsID, feature, displayOrder) VALUES(1234, '1024 MB RAM', 2)
INSERT Features(productsID, feature, displayOrder) VALUES(1234, '80 GB Hard Disk', 3)




Thanks for that great suggestion. But I'm a little confused with the ProductID primary key. The same ProductID will have many features, so how can I keep using the same ProductID on multiple rows? It will need a primary key which doesn't seem possible?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-11-08 : 21:12:56
The ProductID is not the primary key of the Features table. You could add the following as a primary key:

ALTER TABLE Features ADD CONSTRAINT PK_Features PRIMARY KEY (ProductID, Feature)

That will work, but could get clunky and use more index space than necessary. Normalizing a little more like Jeff suggested, something like this:

-- this is a different table, ignore the previous example
CREATE TABLE Features(FeatureID int NOT NULL PRIMARY KEY, FeatureName varchar(50))
-- this is what I should have named it in the first place
CREATE TABLE ProductFeatures(ProductID into NOT NULL, FeatureID int NOT NULL, displayOrder smallint NOT NULL DEFAULT(0))
-- add constraints
ALTER TABLE ProductFeatures ADD CONSTRAINT PK_ProductFeatures PRIMARY KEY (ProductID, FeatureID)
ALTER TABLE ProductFeatures ADD CONSTRAINT FK_ProductFeatures_Product FOREIGN KEY(ProductID) REFERENCES Products(ProductID)
ALTER TABLE ProductFeatures ADD CONSTRAINT FK_ProductFeatures_Features FOREIGN KEY(FeatureID) REFERENCES Features(FeatureID)

-- insert data
INSERT Features(FeatureID, FeatureName) VALUES(1, 'AMD 64 Bit Processor')
INSERT Features(FeatureID, FeatureName) VALUES(2, '1024 MB RAM')
INSERT Features(FeatureID, FeatureName) VALUES(3, '80 GB Hard Disk')
INSERT Features(FeatureID, FeatureName) VALUES(4, '100 GB Hard Disk')

INSERT ProductFeatures(ProductID, FeatureID, displayOrder) VALUES(1234, 1, 1)
INSERT ProductFeatures(ProductID, FeatureID, displayOrder) VALUES(1234, 2, 3)
INSERT ProductFeatures(ProductID, FeatureID, displayOrder) VALUES(1234, 3, 2)

-- select data

SELECT A.ProductID, A.ProdName, C.FeatureName
FROM Products A
INNER JOIN ProductFeatures B ON A.ProductID=B.ProductID
INNER JOIN Features C ON B.FeatureID=C.FeatureID
ORDER BY A.ProductID, C.displayOrder


Normally I'm not a surrogate key fan but in this case the additional table will let you manage features more reliably, efficiently, and easily. You could wrap up the query in a stored procedure:

CREATE PROCEDURE ShowFeatures @productID int AS
SET NOCOUNT ON
SELECT A.ProductID, A.ProdName, C.FeatureName
FROM Products A
INNER JOIN ProductFeatures B ON A.ProductID=B.ProductID
INNER JOIN Features C ON B.FeatureID=C.FeatureID
WHERE A.ProductID=@productID
ORDER BY C.displayOrder
GO
-- call procedure like so:
EXEC ShowFeatures @productID=1234


...and you can avoid embedding large SQL statements in your ColdFusion app code. Jeff's also right about formatting the code in the presentation layer. I don't know ColdFusion at all, but there's probably an easy way to take a data set and format it as an HTML list. If you can format it as a table then it should be very easy to translate it as a list.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-11-08 : 22:03:26
quote:
Originally posted by jsmith8858
Sample data how also help -- it is in the format that Rob indicates (1 description line per row in your table) or is it all stored in 1 row and needs to be broken out?


I just realized that the above is one of the weirdest sentences I've ever written. (the first, part anyway)
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-11-08 : 22:06:18
That's OK, I was drunk when I read it...made perfect sense.
Go to Top of Page

token
Posting Yak Master

133 Posts

Posted - 2005-11-09 : 16:45:11
Thanks for that robvolk! Ok I figured out how to do the bullet-point list. Basically you have another table called Features, which has SpeicifationID, ProductID, and Feature. You do all the relationship making in SQL server. Then when you go to the webpage (in Dreamweaver) you create a query that grabs the features of the product that the user has requested. You then place this information within HTML unordered list tags, and then place that information in HTML table on the webpage. But this will only display the first feature of the product. So you need to create what is known as a Repeat Region Server Behaviour around the HTML table. Then you get all the features listed with a bullet-point!

Woo-hoo!
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-11-09 : 20:31:10
quote:
You do all the relationship making in SQL server.
I find myself strangely aroused by this sentence.

Of course, I don't think it's possible to be NORMALLY aroused by this sentence, but I could be wrong.

Or just weird.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-11-10 : 07:03:55
"I don't think it's possible to be NORMALLY aroused by this sentence"

Unless its a Dating Database ...

Kristen
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-11-10 : 08:24:54
Some of the post topics really crack me up, there's always something like:

"Trouble getting a date"

"Can't find relationships"

"Converting dates"

"Finding a date that is related"

...etc ...

there's at least one per day that makes me giggle.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-11-10 : 14:33:14
"Converting dates"

Is there a prize for the best use of "varchar" in a chatup line?

Kristen
Go to Top of Page
   

- Advertisement -