Click to See Complete Forum and Search --> : [RESOLVED] how to display data from database in a set of 3
omarr226
04-26-2006, 05:01 PM
now here is my problem
i want to know dat how will u display da data from sql database in a set of 3 in one row..
wenever u run a query every entry is displayed in a new row, i want to know dat how will u display da 1st 3 in a single row and ofcourse seperated in 3 columns and den next 3 in 2nd row.
also how will u alternate colors of dese rows, i hav done it in single row but how will u apply da same color in 3 coloumns (same row; where 3 fields are being displayed)
Terrorke
04-27-2006, 01:11 AM
Do you whant to select these 3 records via SQL?
Or do you want to do it in ASP?
omarr226
04-27-2006, 11:27 AM
i want to retrieve via sql query from sql server's table, using asp in dreamweaver
Terrorke
04-27-2006, 11:29 AM
Ok, but I'm not sure if you can do it directly in your query.
Is that your intention?
omarr226
04-27-2006, 02:50 PM
ofcourse u cannot do...dere might be a logic or something like dat..which can divide da records into da set of 3...i.e first 3 records will be shown in 1st row and den next 3 in another row...and just like dat till da end of records...
also i wud like to mention if dere are 100 records den i only want to display da first tweleve...in a set of 3....in each row....hence dere will be altogether 4 rows.....
lmf232s
04-27-2006, 02:57 PM
omarr,
I think i know what you after. I dont think this code will work and it will need to be applied differently but i just wanted to toss something up really quick to give you an idea. It sounds like if your query returned 12 records. You would display the first 3 in a row then the next 3 in another row, eventually you would end up w/ 4 rows and have 3 records in each row.
You just need to loop the records and find when you have looped 3 times, meaning that you have 3 records in that row. Then end the row, start a new row and do it over again.
As for the color of rows check out this post.
http://www.webdeveloper.com/forum/showthread.php?t=103749
or search this forum as this has been asked many times and the answers are always the same but some very to a degree. They all work, its just which method will suit your needs.
Hope this helps.
sSLQ = "SELECT * FROM TABLE"
If Not oRS1.EOF then
'Create your table header
i = 0
Do While Not oRS1.EOF
If i Mod 3 Then
Response.write "<tr>"
End If
Response.write "<td>" & oRS1("Record") & "</td>
If i Mod 3 Then
Response.write "</tr>'
End If
i = i + 1
oRS1.MoveNext
Loop
omarr226
04-30-2006, 06:44 AM
rs.open "select locname from location",con,1,2
response.write"<table>"
Response.write "<tr>"
If Not rs.EOF then
'Create your table header
dim i
i = 1
Do While not rs.EOF
Response.write "<td>" & rs("locname")& "</td>"
If i Mod 3=0 Then
Response.write "</tr>"
Response.write "<tr>"
End If
i = i + 1
rs.MoveNext
Loop
response.write"</table>"
end if
omarr226
04-30-2006, 06:50 AM
now after i have done dis....i want to display da records from da second entry from da table...
i.e i dont want da first record to be displayed
e.g if da first record is Afghanistan and da second record Albania, den da records shoud start to be displayed from Albania and den till da end of records.
lmf232s
04-30-2006, 02:04 PM
omarr,
Not quite sure what you after here. Will Afghanistan all ways be the first record?
If so just find if
Do While Not RS.EOF
If Rs("localname") <> "Afghanistan" Then
'Exexcute your code
Else
'Do nothing because its Afghanistan this time, move to the next record
End if
RS.MoveNext
Loop
Im not that fond of that example because you are hard coding a string name into you logic.
Is this kind of what you were looking for
omarr226
05-01-2006, 05:13 AM
thanx yaar..
but i didnot use dat.....infact i corrected my query..and it was so simple
i just changed my query to
" select * from location where locid<> 1"
haha...
dis happens wen u work 15 hrs a day with 2 hrs sleep only....
haha...
thanx anyway......!!