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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help, with table formatting

Status
Not open for further replies.

samflex

IS-IT--Management
Jun 28, 2004
45
US
Please, please tell me what the heck I am doing wrong.

I am trying to do accomplish 2 things here.

One, make the pictures appear on on 3 columns like:


column1 column2 column2

Almost like
<td></td> <td></td> <td></td>

So far it is appearing on 2 columns

The other thing I am trying to accomplish here is to ensure that description (in this case, More) appear under the picture like:

picture1 picture2 picture3
discription discription discription


Can you please help me again!

I thank you for all the great help on this forum.

Here is the code that I am struggling with.

Code:
Response.Buffer = true
Dim catid, strcat
catid = Request.QueryString("id")
strcat = Request.QueryString ("cat")

If catid = "" OR (IsNumeric(catid) = false) Then
	Response.Redirect "home.asp"
End if

Dim catname, productslist
sub productInfo(connObj,category)
	q = chr(34)
	set cmd = server.CreateObject("ADODB.Command")
	cmd.ActiveConnection = connObj
	cmd.CommandText = "qryProdsCategory"
	cmd.CommandType = adCmdStoredProc
	set param = cmd.CreateParameter("theCategory",adInteger,adParamInput,4)
	cmd.Parameters.Append(param)
	cmd("theCategory") = Cint(category)
	set rs = server.CreateObject("ADODB.Recordset")
	set rs = cmd.Execute

	if not rs.EOF then
		catname = rs("catdescription")
		strHTML = "<table width='100%' border=0 cellspacing=0 cellpadding=0>"
		strHTML = strHTML & "<tr>"

		i = 1
		while not rs.EOF
			strHTML = strHTML & "<td class=bodytextcolor width='33%' align=center>" & vbcrlf
			strHTML = strHTML & "<img src=" & q& "images/small/" & rs("cimageurl") &q& " align=" & q& "left"& q & ">" & vbcrlf
			strHTML = strHTML & "<br><br>" & rs("cname") & " " & vbcrlf
			strHTML = strHTML & "<p><font size=-1><a href="&q&"product.asp?id=" & rs("catalogID") &q&">More &gt;&gt;&gt;</a></font></p>" & vbcrlf
			if (i mod 2) = 0 then
				strHTML = strHTML & "</td></tr>" & vbcrlf
			end if
			i = i + 1
			rs.MoveNext
		wend

		strHTML = strHTML & ""
	else
		strHTML = "Product information not found."
		catname = "Error"
	end if
		productslist = strHTML
	rs.Close
	set rs = nothing
	set cmd = nothing

end sub
 
Well,m for one thing you have 1 mod 2 as the point to add an end row tag. Changing this to 3 would be the beginning of a solution.
However, you never actually output a tr tag to start the rows, and while most browsers will let you output messy code like this, it will cause longer resolution times and also is a very bad habit. Your also only ending your column tags when your ending the row, another bitofmessiness that will cause the browser extra time to render properly (or possibly even to mis-render it)

I would suggest altering your code like so:
Code:
[highlight]Dim numCols
numCols = 3 'easy way to change number of columns, just change this value[/highlight]
while not rs.EOF
            [highlight]If i mod numCols = 0 The strHTML = strHTML &  "<tr>"[/highlight]
            strHTML = strHTML & "<td class=bodytextcolor width='33%' align=center>" & vbcrlf
            strHTML = strHTML & "<img src=" & q& "images/small/" & rs("cimageurl") &q& " align=" & q& "left"& q & ">" & vbcrlf
            strHTML = strHTML & "<br><br>" & rs("cname") & " " & vbcrlf
            strHTML = strHTML & "<p><font size=-1><a href="&q&"product.asp?id=" & rs("catalogID") &q&">More &gt;&gt;&gt;</a></font></p>" & vbcrlf
            [highlight]strHTML = strHTML & "</td>"[/highlight]
            if (i mod [highlight]numCols[/highlight]) = [highlight]numCols - 1[/highlight] then 
                 strHTML = strHTML & [highlight]"</tr>"[/highlight] & vbcrlf
            end if
            i = i + 1
            rs.MoveNext
        wend
        [highlight]'finish an open row if there is one still open
        If i mod numCols > 0 Then strHTML = strHTML & "</tr>"[/highlight]

These changes should amke it easier to change the number of columns as well as generate better formatted HTML output.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
Help, the rampaging, spear-waving, rabid network gnomes are after me!
 
hi Tarwn!

Once again, you managed to make it seem very easy with your comments.

I put together your piece with mine but I can't even see anything.

The screen is blank when I run it.

If have an extra second, can you please tell me where I messed up?

Thanks so much (again) for all you do.

Code:
Response.Buffer = true
Dim catid, strcat
catid = Request.QueryString("id")
strcat = Request.QueryString ("cat")

If catid = "" OR (IsNumeric(catid) = false) Then
	Response.Redirect "home.asp"
End if

Dim catname, productslist
sub productInfo(connObj,category)
	q = chr(34)
	set cmd = server.CreateObject("ADODB.Command")
	cmd.ActiveConnection = connObj
	cmd.CommandText = "qryProdsCategory"
	cmd.CommandType = adCmdStoredProc
	set param = cmd.CreateParameter("theCategory",adInteger,adParamInput,4)
	cmd.Parameters.Append(param)
	cmd("theCategory") = Cint(category)
	set rs = server.CreateObject("ADODB.Recordset")
	set rs = cmd.Execute

	if not rs.EOF then
		catname = rs("catdescription")
		strHTML = "<table width='100%' border=0 cellspacing=0 cellpadding=0>"
		strHTML = strHTML & "<tr>"

		i = 1

**************************************************
Below is your piece integrated with my piece above
***************************************************
Dim numCols
numCols = 3 'easy way to change number of columns, just change this value
while not rs.EOF
            If i mod numCols = 0 Then strHTML = strHTML &  "<tr>"
            strHTML = strHTML & "<td class=bodytextcolor width='33%' align=center>" & vbcrlf
            strHTML = strHTML & "<img src=" & q& "images/small/" & rs("cimageurl") &q& " align=" & q& "left"& q & ">" & vbcrlf
            strHTML = strHTML & "<br><br>" & rs("cname") & " " & vbcrlf
            strHTML = strHTML & "<p><font size=-1><a href="&q&"product.asp?id=" & rs("catalogID") &q&">More &gt;&gt;&gt;</a></font></p>" & vbcrlf
            strHTML = strHTML & "</td>"
            if (i mod numCols) = numCols - 1 then
                 strHTML = strHTML & "</tr>" & vbcrlf
            end if
            i = i + 1
            rs.MoveNext
        wend
        'finish an open row if there is one still open
        If i mod numCols > 0 then strHTML = strHTML & "</tr>"
        end if
    end sub
 
Ok, one more minor correction, start i off = 0 instead of 1 so it will print the first tr correctly (as well as the later ones).

You also still need an end table tag before that end if near the bottom, I didn't include it in my changes because I thought you already had one.


You may want to also put an Else case in there, maybe somehting like:
Code:
...
...
			rs.MoveNext
		wend
		'finish an open row if there is one still open
		If i mod numCols > 0 then strHTML = strHTML & "</tr>"
		strHTML = strHTML & "</table>"
	else
		strHTML = "<b>Sorry, No records To Display</b>"
	end if
end sub

Now the major reason you aren't seeing anything is because while you are making this string called strHTM<L you aren't ever actually printing it. In fact I don't see you calling the sub anywhere either. My suggestion would eb to change this to a function and make the function return strHTML:
Code:
[highlight]Function[/highlight] productInfo(connObj,category)
	[highlight]'it's always better to declare everything, you should read up on Option Explicit
	'	and how it helps efficiency
	Dim q, cmd, rs, param, catname, strHTML, i[/highlight]

    q = chr(34)
    set cmd = server.CreateObject("ADODB.Command")
    cmd.ActiveConnection = connObj
    cmd.CommandText = "qryProdsCategory"
    cmd.CommandType = adCmdStoredProc
    set param = cmd.CreateParameter("theCategory",adInteger,adParamInput,4)
    cmd.Parameters.Append(param)
    cmd("theCategory") = Cint(category)
    set rs = server.CreateObject("ADODB.Recordset")
    set rs = cmd.Execute

    if not rs.EOF then
        catname = rs("catdescription")
        strHTML = "<table width='100%' border=0 cellspacing=0 cellpadding=0>"
        strHTML = strHTML & "<tr>"

        i = 0

		**************************************************
		Below is your piece integrated with my piece above
		***************************************************
		Dim numCols
		numCols = 3 'easy way to change number of columns, just change this value
		while not rs.EOF
			If i mod numCols = 0 Then strHTML = strHTML &  "<tr>"
			strHTML = strHTML & "<td class=bodytextcolor width='33%' align=center>" & vbcrlf
			strHTML = strHTML & "<img src=" & q& "images/small/" & rs("cimageurl") &q& " align=" & q& "left"& q & ">" & vbcrlf
			strHTML = strHTML & "<br><br>" & rs("cname") & " " & vbcrlf
			strHTML = strHTML & "<p><font size=-1><a href="&q&"product.asp?id=" & rs("catalogID") &q&">More &gt;&gt;&gt;</a></font></p>" & vbcrlf
			strHTML = strHTML & "</td>"
			if (i mod numCols) = numCols - 1 then
				strHTML = strHTML & "</tr>" & vbcrlf
			end if
			i = i + 1
			rs.MoveNext
		wend
		'finish an open row if there is one still open
		If i mod numCols > 0 then strHTML = strHTML & "</tr>"
		strHTML = strHTML & "</table>"
	else
		strHTML = "<b>Sorry, No records To Display</b>"
	end if

	[highlight]productInfo = strHTML
End Function[/highlight]

[highlight]'then you need to call the function and print it's returned string (strHTML)
Dim tConn
Set tConn = Server.CreateObject("ADODB.Connection")
tConn.Open("your connection string here")

Response.Write ProductInfo(tConn, strcat)

'clean up
tConn.Close
Set tConn = Nothing

There are a couple other places you should have cleanup code, it's generally a good idea to set any object = Nothig when your done with it to allow the server to release that memory faster. Closing open connections also helps because it releases whatever your connected to, allowing it to accept other incoming connections faster.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
Help, the rampaging, spear-waving, rabid network gnomes are after me!
 
That's it!
It's working beautifully!!

Thank you so very much.
I am really learning from this forum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top