www.webdeveloper.com
Results 1 to 10 of 10

Thread: [RESOLVED] how to display data from database in a set of 3

  1. #1
    Join Date
    Apr 2006
    Posts
    73

    resolved [RESOLVED] how to display data from database in a set of 3

    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)

  2. #2
    Join Date
    Mar 2006
    Posts
    591
    Do you whant to select these 3 records via SQL?
    Or do you want to do it in ASP?

  3. #3
    Join Date
    Apr 2006
    Posts
    73
    i want to retrieve via sql query from sql server's table, using asp in dreamweaver

  4. #4
    Join Date
    Mar 2006
    Posts
    591
    Ok, but I'm not sure if you can do it directly in your query.
    Is that your intention?

  5. #5
    Join Date
    Apr 2006
    Posts
    73
    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.....

  6. #6
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    1,607
    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/sh...d.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.


    Code:
    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

  7. #7
    Join Date
    Apr 2006
    Posts
    73

    da correct code is dis>>>>>

    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

  8. #8
    Join Date
    Apr 2006
    Posts
    73
    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.

  9. #9
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    1,607
    omarr,

    Not quite sure what you after here. Will Afghanistan all ways be the first record?
    If so just find if
    Code:
    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

  10. #10
    Join Date
    Apr 2006
    Posts
    73
    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......!!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles