2

I apologize if this has already been answered (I'm sure it has somewhere). I'm looking for a way to dynamically populate a set of columns from a database while keeping them even (or close). I'm using asp classic with SQL Server 2008 to get the data.

The example below is for 2 columns just to try to keep it simple. I was thinking of finding a way to check the number of data entries I'm selecting and dividing by 2 to evenly populate the columns. And if the number of entries was something like 13 then the first column would have 7 and the second 6. I'm fairly new to asp and javascript so nothing is really jumping out at me. Any help or guidance in the right direction would be greatly appreciated. Thank you.

<html >
<head>

<style type="text/css">
    ul#list { list-style-type: none; }
</style>

</head>
<body>

<table border="0" cellspacing="0" cellpadding="0" width="100%" >
    <tr>
        <div>
            <td>
                <div style="float: left; width:30%;">
                    <ul id="list">                            
                        <li>Left Item 1</li>            
                        <li>Left Item 2</li>            
                        <li>Left Item 3</li>            
                        <li>Left Item 4</li>            
                        <li>Left Item 5</li>            
                    </ul>                           
                </div>

                <div style="float: left; width:30%;">
                    <ul id="list" >                            
                        <li>Middle Item 1</li>          
                        <li>Middle Item 2</li>          
                        <li>Middle Item 3</li>          
                        <li>Middle Item 4</li>          
                        <li>Middle Item 5</li>          
                    </ul>                           
                </div> 

            </td>
     </tr>
 </table>    

</body>    
</html>
bratak
  • 80
  • 13
  • why not number the div's and append content via jQuery on fetch? right now your table may have 20 columns... this makes a solution attempt more difficult. also please refrain from giving the same id multiple times... your id="list" is not unique :(, btw. how do you fill the data?? from "top left to bottom right" or from "left top to right bottom"? – Vogel612 Sep 04 '13 at 06:53
  • what happens when you got 11 records?? – Vogel612 Sep 05 '13 at 07:25
  • Based on what I posted it should show Columns (1,2,3) = (4,4,3). I divide 11/3 and for the first column round up from 3.7 to 4. Then I get the NewTotal as the remainder (7 in this case) and subtract that from 11 = 4 for the second column. Then the remaining 3 go in the third column. Maybe I shouldn't have just stuck etc... in the code above and shown all 3 columns being made. – bratak Sep 05 '13 at 14:51
  • you could post that as an answer and accept it. people don't like to see questions answered by editing... (well i made that mistake too) – Vogel612 Sep 05 '13 at 14:59
  • Oh ok oops. I'll remember that from now on. Thanks! – bratak Sep 06 '13 at 13:53

1 Answers1

2

UPDATE: In case anyone else wants to know, here's what I ended up doing. I use the approach in Row Offset in SQL Server.

I got the total number of rows returned

SELECT COUNT(*) AS count from table1 ... and then divvied them up evenly among the columns.

I have 3 columns so I divided the total count by 3 and rounded the first column up using a RoundUp function described here http://www.bennysutton.com/Active-Server-Pages/Round-Up-Numbers.aspx

TotalCount = Query01.Fields.Item("count").Value
FirstColumn = RoundUp(TotalCount / 3 , 0)
NewTotalCount = TotalCount - FirstColumn
SecondColumn = TotalCount - NewTotalCount 
ThirdColumn = TotalCount - (FirstColumn + SecondColumn)

Then I would construct the Row Offset Query02 changing @startRow and @endRow to being the values above. From 1 to FirstColumn, then (FirstColumn + 1) to (FirstColumn + SecondColumn) etc....

To answer @Vogel612, I wanted to fill the first column then the second etc.. from top down left to right.

<table border="0" cellspacing="0" cellpadding="0" width="100%" >
    <tr>
     <div>
       <td>
         <div style="float: left; width:30%;">
           <ul id="list">
           <%Do Until Query02.EOF
                Response.Write"<li> " & Query02.Fields.Item("foo") & " </li>"
            Query02.MoveNext
            LOOP
           Query02.Close%>                            
          </ul>
            <ul id="list">
               etc.....
            </ul> 
         </div>
       </td>
      </tr>
 </table>

Also I see the issue with id="list". I was trying that to get rid of the bullet points.

Community
  • 1
  • 1
bratak
  • 80
  • 13