webForumDet fria alternativet

Dynamisk tabell

ASPur ASP

8 svar · 482 visningar · startad av devotion

Medlem sedan jan. 20013 582 inlägg
Frågan#1

Hepp!

Har en liten käck fråga. Jag vill göra en dynamsik tabell som loopar ut tabellrubriker och tabellceller...

Tabellrubrikerna <th> är ju inga problem enligt nedanstående kod. datat hämtas från tblSupplier och alla leverantörerna blir tabellrubriker. Problemet är att jag inte vet hur jag ska göra för att loopa ut motsvarnde antal <td>... I <td> ska uppgifter som hör till leverantören i tabellrubriken stå. tex priser.

Hur får jag till detta?

Dvs

  1. rätt antal <td>
  2. någon typ av kontroll så det verkligen är leverantör 1 uppgifter som står i kolumnen.
	<table>
		<caption>
		Sammanst&auml;llning
		</caption>
			<thead>
				<tr>
					<th>Ben&auml;mning</th>
					<th>Enhet</th>
					<%
					Do While not objRS.EOF		
						iSupplierCounter = iSupplierCounter + 1
						
						sSupplier = "" & objRS("supplierName")
						%>
						<th><% =sSupplier %></th>
						<%
						objRS.MoveNext
					Loop
					
					objRS.Close
					Set objRS = Nothing
					%>
					<th>Antal</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>EKLK 3G 1,5 R50</td>
					<td>m</td>
					[b] dynamskt antal:<td></td>[/b]
					<td>textfält</td>
				</tr>
			</tbody>
	</table>

Mvh
Henrik

Medlem sedan dec. 19996 721 inlägg
#2

Loopa igenom objRS igen och sök ut relevanta uppgifter på rätt ställe.

Medlem sedan jan. 20013 582 inlägg
#3

Hej emission! :)

Skulle du kunna utveckla det lite?

Mvh
Henrik

Medlem sedan dec. 19996 721 inlägg
#4

Eller snarare...

Om det bara ska vara en rad/produkt i tabellen, så kan du ju söka ut både produktinformation och leverantörer i samma fråga och loopa igenom samma recordset två gånger. Första gången plockar du ut leverantörsnamnet och andra gången produktinfon.

Medlem sedan jan. 20013 582 inlägg
#5

ok!
Ska testa lite...

Kanske återkommer i ärendet.. ;)

Tack så länge!

Mvh
Henrik

Medlem sedan jan. 20013 582 inlägg
#6

Hepp igen!

Har testat lite

Har följande kod:

	<table>
		<caption>
		Sammanst&auml;llning
		</caption>
			<thead>
				<tr>
					<th>Ben&auml;mning</th>
					<th>Enhet</th>
					<%
					sSQL = "SELECT tblArticle.articleUnit, tblArticle.articleName, tblPrice.articleNumber, tblCategory.CategoryName, tblSupplier.SupplierName, " &_
							"tblPrice.articlePrice, tblDiscount.articleDiscount " &_
							"FROM tblSupplier " &_
							"LEFT OUTER JOIN tblDiscount " &_
							"INNER JOIN tblCategory ON tblDiscount.categoryNumber = tblCategory.categoryNumber AND tblDiscount.supplierId = tblCategory.supplierId " &_
							"INNER JOIN tblCart " &_
							"INNER JOIN tblArticle ON tblCart.articleName = tblArticle.articleName " &_
							"INNER JOIN tblPrice ON tblArticle.articlenumber = tblPrice.articleNumber ON tblCategory.categoryNumber = tblPrice.articleCategoryNumber " &_
							"AND tblCategory.supplierId = tblPrice.articleSupplierId ON tblSupplier.SupplierId = tblPrice.articleSupplierId " &_
							"ORDER BY tblPrice.articlePrice"
							
					Set objRS = objConn.Execute (sSQL)

					Do While not objRS.EOF		

						sSupplier = "" & objRS("supplierName")
						%>
						<th><% =sSupplier %></th>
						<%
						objRS.MoveNext
					Loop
					
					%>
					<th>Antal</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td>EKLK 3G 1,5 R50</td>
					<td>m</td>
					<%
					Set objRS = objConn.Execute (sSQL)

					Do While not objRS.EOF		
						
						iFieldCounter = iFieldCounter + 1
						sSupplier = "" & objRS("articlePrice")
						%>
						<td><a href="" onclick="return showResults(event,this)"><% =objRS("articlePrice") %> kr</a><input type="hidden" name="foo<% =iFieldCounter %>"></td>
						<%
						objRS.MoveNext
					Loop
					
					objRS.Close
					Set objRS = Nothing
					%>
					<td><input name="" type="text"></td>
				</tr>
			</tbody>
	</table>

Det fungerar om jag bara en artikel i tblCart... Lägger jag i flera där så upprepas leverantörerna...

Är jag på rätt spår?

Bifogar lite skärmdumpar!

Mvh
henrik

dump-2.jpgdump-1.jpg
Medlem sedan jan. 20013 582 inlägg
#7

Ingen som har någon smart idé?

Mvh
Henrik

Medlem sedan jan. 20013 582 inlägg
#8

Hej! :)

Nu har jag gjort en tabell med en leverantör (låst i SQL-frågan) och en artikel i tblCart...

Det funkar ju fint. Men hur i all sin dar får man till alt dynamiskt?

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<script type="text/javascript">
function showResults(e,a)
{
  var left, top;
  if (window.event){
    left = window.event.clientX;
    top  = window.event.clientY;
  } else if (e){
    left = e.pageX;
    top  = e.pageY;
  }

  if (left && top){
    window["a"] = a;
    elm.style.left = left + "px";
    elm.style.top  = top + "px";
    elm.style.visibility = "visible";
  }

  return false;
}

window.onload = function()
{
  window["elm"] = document.getElementById("result");
}

document.onclick = function(e)
{
  var tmp = window.event ? window.event.srcElement : e ? e.target : 0,
      fnd = false;
  if (tmp){
    while (tmp){
      if (tmp == elm || (typeof a != "undefined" && tmp == a)) {
        fnd = true;
        break;
      }
      tmp = tmp.parentNode;
    }
  }

  if (!fnd) elm.style.visibility = "hidden";
}

function changeValue(p,c,s,i)
{
  if (a && elm){
    a.innerHTML = p + " - " + c + " - " + s + " kr";
    document.forms[0].elements[i].value = c;
    elm.style.visibility = "hidden";
  }
}

</script>
<link href="../css/cart.css" rel="stylesheet" type="text/css">
</head>
<body>
<!--#include virtual="/includes/functions.asp" -->

<%

'Deklarera variabler
'*******************
Dim objConn, objRS, sSQL

' Öppna databasen
' ***************
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = Application("sConn")
objConn.Open

%>

<form method="post" action="taemot.asp">
	<table>
		<caption>
		Sammanst&auml;llning
		</caption>
			<thead>
				<tr>
					<th>Ben&auml;mning</th>
					<th>Enhet</th>
					<th>Solar</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<%
					sSQL = 	"SELECT tblArticle.articleName, tblArticle.articleUnit, tblPrice.articlePrice, tblSupplier.SupplierName, " &_
					"tblCart.articleAmount, tblSupplier.SupplierId, tblCategory.CategoryName, tblPrice.articleNumber " &_
					"FROM tblArticle " &_
					"INNER JOIN tblPrice ON tblArticle.articlenumber = tblPrice.articleNumber " &_
					"INNER JOIN tblSupplier ON tblPrice.articleSupplierId = tblSupplier.SupplierId " &_
					"INNER JOIN tblCart ON tblArticle.articleName = tblCart.articleName " &_
					"INNER JOIN tblCategory ON tblPrice.articleSupplierId = tblCategory.supplierId AND tblPrice.articleCategoryNumber = tblCategory.categoryNumber " &_
					"WHERE (tblSupplier.SupplierId = 1) " &_
					"ORDER BY tblPrice.articlePrice"

					Set objRS = objConn.Execute (sSQL)

					dArticlePrice =  cdbl(objRS("articlePrice"))		
					sCategoryName = objRS("CategoryName")	
					sArticleNumber = objRS("articleNumber")	
					sArticleName = 	objRS("articleName")
					sArticleUnit = 	objRS("articleUnit")
					iSupplierId = objRS("SupplierId")
					response.write "supplierId: " & isupplierId
					%>

					<td><% =sArticleName %></td>
					<td><% =sArticleUnit %></td>
					<td><a href="" onclick="return showResults(event,this)" style="color:blue;text-decoration:none"><% =sCategoryName & "-" & sArticleNumber & "-" & dArticlePrice %> kr</a><input type="hidden" name="articleNumber" value="<% =sArticleNumber %>"><input type="hidden" name="supplierId" value="<% =isupplierId %>"></td>
				</tr>
			</tbody>
	</table>
	
	<div id="result">
		<ul>
			<%
			Set objRS = objConn.Execute (sSQL)
			
			Do while not objRS.EOF
			
				dArticlePrice =  cdbl(objRS("articlePrice"))		
				sCategoryName = objRS("CategoryName")	
				sArticleNumber = objRS("articleNumber")	
				sArticleName = 	objRS("articleName")
				sArticleUnit = 	objRS("articleUnit")
				
				%>
				<li><span onclick="changeValue('<% =sCategoryName %>','<% =sArticleNumber %>','<% =dArticlePrice %>','articleNumber')" style="cursor:pointer;color:blue"><% =sCategoryName & "-" & sArticleNumber & "-" & dArticlePrice %> kr</span></li>
				<%
				objRS.MoveNext
			Loop
			%>
		</ul>
	</div>
<input name="" type="submit" value="Submit">
</form>

<%
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
</body>
</html>

Resultatet ser ni här:
http://80.73.182.130/testscript/ruta.asp

Bifogar även en bild på hur jag "vill" ha det!

Mvh
Henrik

önskedröm.jpg
Medlem sedan jan. 20013 582 inlägg
#9

Hej!

Denna tråd har blivit löst i en annan tråd....

http://www.webforum.nu/showthread.php?p=1199402#post1199402

Mvh
Henrik

140 ms totalt · 3 externa anrop · v20260731065814-full.25f56b17
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
136 ms — hämta tråd, inlägg och bilagor (db)