#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Date Array Content Display Issue Complicated


    Hi this is my first post and I'm quite stuck if I'm honest and I'm relatively new to ASP that being said I am not looking for a simple solution as any complexities will aid in my learning process

    Using Jscript in my ASP

    Situation:
    I have a 2 dimensional array that needs to be printed out into a table.

    Array structure:
    array[id][monthNumber] = value
    My id does not start at 0(it can tho) the first id is in fact 15 monthNumber can be anything within a 4 month period so it can be 4 - 7 or 11 - 2. Value is just a number

    Eg array elements:
    array[15][8] = 19
    array[15][9] = 52
    array[15][10] = 14
    array[15][11] = 98

    array[20][8] = 125
    array[20][9] = 254
    array[20][10] = 7
    array[20][11] = 9

    Problem:
    I need to display this information like this
    Code:
    <table border="1" cellpadding="2" cellspacing="0">
    		<tr>
    			<td>ID</td>
    			<td>August</td>
    			<td>September</td>
    			<td>October</td>
    			<td>November</td>
    		</tr>
    		<tr>
    			<td>15</td>
    			<td>19</td>
    			<td>52</td>
    			<td>14</td>
    			<td>98</td>
    		</tr>
    		<tr>
    			<td>20</td>
    			<td>125</td>
    			<td>254</td>
    			<td>7</td>
    			<td>9</td>
    		</tr>
    	</table>
    As you can see with the IDs 20 follows 15 so there can be undefined elements. I do have an array with month names in to display the appropriate month name based on the monthNumber element of my array
    Code:
    var months = new Array();
    months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
    As I said before the month period can vary from 1 month to a 4 month period

    Oh and the table needs to be produced server side

    Will appreciate any solutions
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,424
    Rep Power
    4539
    Using Jscript in my ASP
    Well, I won't be able to help much then, sorry.

    In general you'd construct a loop that will iterate through your array, and at each node your code will generate the appropriate html to get sent to the browser for that node.
    ======
    Doug G
    ======
    The man who doesn't read good books has no advantage over the man who can't read them.
    --Mark Twain
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0
    Originally Posted by Doug G
    Well, I won't be able to help much then, sorry.

    In general you'd construct a loop that will iterate through your array, and at each node your code will generate the appropriate html to get sent to the browser for that node.
    You could write it in VBScript or any other language I can always switch it to JScript I've tried dozens of loop things and I'm getting no where:-(
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    3
    Rep Power
    0

    Solved It :-)


    Code:
    var output = displayArray(detailArray, drStart, drEnd, nameArray);
    
    function displayArray(chat, start, end, name){
    	var table = ""
    	table = "<table border=1 cellpadding=2 cellspacing=0 width=550 id=dis><tr bgcolor=#8c929c><td style='color: #FFF;'><b>User</b></td>"
    	
    	if((start >=10)&&(end >= 1)&&(end <= 4)){
    		temp = 13
    		for (x = start; x <= temp; x++){
    			if (x == 13){
    				temp = end
    				x = 1 
    			}
    			table += "<td align=center style='color: #FFF;'><b>" + months[x - 1] + "</b></td>"
    		}
    	}else{
    		for (x = start; x <= end; x++){
    			table += "<td align=center style='color: #FFF;'><b>" + months[x - 1] + "</b></td>"
    		}
    	}
    	
    	table += "</tr>"
    	
    	for (i = 1; i < chat.length; i++){
    		if (typeof(chat[i]) != "undefined"){
    			table += "</tr><tr><td>" + name[i] + "</td>"
    			if((start >=10)&&(end >= 1)&&(end <= 4)){
    				temp = 13
    				for (x = start; x <= temp; x++){
    					if (x == 13){
    						temp = end
    						x = 1 
    					}
    					if (typeof(chat[i][x]) != "undefined"){ 
    						table += "<td>" + chat[i][x] + "</td>"
    					}else{
    						table += "<td>&nbsp;</td>"
    					}
    				}
    			}else{
    				for (x = start; x <= end; x++){
    					if (typeof(chat[i][x]) != "undefined"){ 
    						table += "<td>" + chat[i][x] + "</td>"
    					}else{
    						table += "<td>&nbsp;</td>"
    					}
    				}
    			}
    		}
    	}
    	
    	table += "</tr></table>"
    	return table
    }
    
    function dateRange(sDate, eDate){
    	tempS = new Date(sDate);
    	tempE = new Date(eDate);
    	
    	drStart = tempS.getMonth() + 1;
    	drEnd = tempE.getMonth() + 1;
    }
  8. #5
  9. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,424
    Rep Power
    4539
    Thank you for posting your solution!
    ======
    Doug G
    ======
    The man who doesn't read good books has no advantage over the man who can't read them.
    --Mark Twain

IMN logo majestic logo threadwatch logo seochat tools logo