---
title: "Loopa ut tabeller."
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/77721-loopa-ut-tabeller"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "Runken"
published: "2003-05-22T09:18:33.000Z"
updated: "2003-05-24T23:46:37.000Z"
replies: 14
views: 298
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/77721-loopa-ut-tabeller"
---

# Loopa ut tabeller.

## #1 — Runken, 2003-05-22T09:18Z

Tjena!
När man kommer in på vår produktsida så skall alla produkter hämtas från en databas och läggas i en tabell. Alltså varje produkt skall få en egen tabell. Vi vill alltså hela yttre tabellen med dess innehåll skall loopas så många gånger som det finns varor. 

Vår kod:

```
<table width="150" border="0">
            <tr>
              <td><table width="150" border="0">
			  <tr><td>

<%
	strsqlbild = "SELECT Bilder FROM Product where Bilder != 'NULL'"
	set recset = conn.Execute(strsqlbild)
		If NOT recset.EOF Then arrRecset = recset.GetRows()
		recset.Close : Set recset = Nothing
If IsArray(arrRecset) Then

	For i = 0 To UBound(arrRecset, 2)%>
		<p align="center"><strong>Lampa</strong></p></td></tr>
    <tr>
    <td>
		
		
<%		sokvag = arrRecset(0,i)
		Response.Write"<img src= """& sokvag &""">"
		  Next
		  End if
		 
	%>
	</td> <td>
	<form action="Produkter.asp" method="post" name="produkt1">
	<table width="150" border="0">
                                                <tr> 
                          <td height="26" colspan="2">Storlek</td>
                          <td>
						  <%
						  
strSQL = "SELECT storlekfarg FROM product WHERE Produktnamn = 'lampa1'"
Set objRS = conn.Execute(strSQL)
	If NOT objRS.EOF Then arrstorlekfarg = objRS.GetRows()
objRS.Close : Set objRS = Nothing

   If IsArray(arrstorlekfarg) Then

	Response.Write "<select name=""strl1""> "

	For j = 0 To UBound(arrstorlekfarg, 2)
		strStorlek = arrstorlekfarg(0,j)
		Response.Write "<option value="""& strStorlek &""">"& strStorlek &"</option>"
	Next

	Response.Write "</select>"

   End If
%>
</td>
                        </tr>
                       
                      </table>
					  </form>
<%conn.Close
Set conn = Nothing%>
</td>
  </tr>
</table>

</td>
            </tr>
         </table>
		  
        </div>
   </tr>
  </table>
  </div>
```

Mvh

Permalänk: https://www.webforum.nu/p/77721

## #2 — m_soderlund, 2003-05-22T09:20Z

Glöm ej att använda kod-taggen!

```
<table width="150" border="0"> 
<tr> 
<td><table width="150" border="0"> 
<tr><td> 

<% 
strsqlbild = "SELECT Bilder FROM Product where Bilder != 'NULL'" 
set recset = conn.Execute(strsqlbild) 
If NOT recset.EOF Then arrRecset = recset.GetRows() 
recset.Close : Set recset = Nothing 
If IsArray(arrRecset) Then 

For i = 0 To UBound(arrRecset, 2)%> 
<p align="center"><strong>Lampa</strong></p></td></tr> 
<tr> 
<td> 

<% sokvag = arrRecset(0,i) 
Response.Write"<img src= """& sokvag &""">" 
Next 
End if 

%> 
</td> <td> 
<form action="Produkter.asp" method="post" name="produkt1"> 
<table width="150" border="0"> 
<tr> 
<td height="26" colspan="2">Storlek</td> 
<td> 
<% 

strSQL = "SELECT storlekfarg FROM product WHERE Produktnamn = 'lampa1'" 
Set objRS = conn.Execute(strSQL) 
If NOT objRS.EOF Then arrstorlekfarg = objRS.GetRows() 
objRS.Close : Set objRS = Nothing 

If IsArray(arrstorlekfarg) Then 

Response.Write "<select name=""strl1""> " 

For j = 0 To UBound(arrstorlekfarg, 2) 
strStorlek = arrstorlekfarg(0,j) 
Response.Write "<option value="""& strStorlek &""">"& strStorlek &"</option>" 
Next 

Response.Write "</select>" 

End If 
%> 
</td> 
</tr> 

</table> 
</form> 
<%conn.Close 
Set conn = Nothing%> 
</td> 
</tr> 
</table> 

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

</div> 
</tr> 
</table> 
</div>
```

Återkommer.

Permalänk: https://www.webforum.nu/p/1058283

## #3 — m_soderlund, 2003-05-22T09:33Z

Nåt sånt här kanske:

```
<table width="150" border="0"> 
<tr> 
<td><table width="150" border="0"> 
<tr><td>
<%
Dim Cn, Rs, arrRecs, i, p(1)
Set Cn = Server.CreateObject("ADODB.Connection") 
Cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db_.mdb")

Set Rs = Cn.Execute(""SELECT Bilder,storlekfarg FROM Product where Bilder != 'NULL'" AND Produktnamn = 'lampa1') 

If Rs.EOF Then 
Rs.Close : Set Rs = Nothing 
Cn.Close : Set Cn = Nothing
Response.Write "Inga poster än.." 
 

Else arrRecs = Rs.GetRows() 
Rs.Close : Set Rs = Nothing 
Cn.Close : Set Cn = Nothing 

For i = 0 To UBound(arrRecs,2)
Response.Write "<p align=""center""><strong>Lampa</strong></p></td></tr> 
<tr><td>"
 
p(0) = arrRecs(0,i)
p(1) = arrRecs(1,i)

Response.Write"<img src= """& sokvag &"""></td><td> 
<form action=""Produkter.asp"" method=""post"" name=""produkt1"">" & _
"<table width=""150"" border=""0""> 
<tr> 
<td height=""26"" colspan=""2"">Storlek</td> 
<td>" & _
"<select name=""strl1""><option value="""& p(1) &""">"& p(1) &"</option></select>" & _
"</td> 
</tr> 

</table> 
</form>"

Next

End If
%>
 
</td> 
</tr> 
</table> 

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

</div> 
</tr> 
</table> 
</div>
```

Phu! Hoppas att det fungerar nu.

Permalänk: https://www.webforum.nu/p/1058296

## #4 — Runken, 2003-05-22T09:36Z

Tack så mycket för det! Ska testa..

Permalänk: https://www.webforum.nu/p/1058301

## #5 — Runken, 2003-05-22T13:43Z

Hej igen!

Får det inte att fungera riktigt, säkert mycket pga att vi inte riktigt förstår vad som händer. Men får i a f felmeddelandet:

```
Feltyp:
Kompileringsfel i Microsoft VBScript (0x800A0409)
Oavslutad strängkonstant
/TMPcb4mpfaj4d.asp, line 111, column 74
Response.Write "<p align=""center""><strong>Lampa 1</strong></p></td></tr>
-------------------------------------------------------------------------^
```

alltså när bara lampa ska skrivas ut. Provade att ta bort den raden men fick då samma fel på

```
Response.Write"<img src= """& sokvag &"""></td><td>
--------------------------------------------------^

raden. Vad gör vi för fel? Undrar också vad:

p(0) = arrRecs(0,i)
p(1) = arrRecs(1,i)
```

gör? Är p(0) index 0?

Mycket tacksamma för svar

Mvh

Permalänk: https://www.webforum.nu/p/1058506

## #6 — crisse6, 2003-05-22T14:03Z

lagg till " i slutet pa varje ;)

alltsa sa har:
Response.Write "\<p align=""center""\>\<strong\>Lampa 1\</strong\>\</p\>\</td\>\</tr\> **"**

Permalänk: https://www.webforum.nu/p/1058522

## #7 — Runken, 2003-05-22T15:33Z

Tack för svaret men tyvärr hade vi skrivit ut situationstecknen, det var bara att det inte stod med i felmeddelandet.

Mvh

Permalänk: https://www.webforum.nu/p/1058584

## #8 — @nders, 2003-05-22T15:35Z

Hur ser aktuell kod ut nu då?

Permalänk: https://www.webforum.nu/p/1058588

## #9 — Runken, 2003-05-22T21:23Z

Aktuell kod:

```
<table width="150" border="0"> 
<tr> 
<td><table width="150" border="0"> 
<tr><td>
<%
Dim conn, Rs, arrRecs, i, p(1)
Set conn = createobject("ADODB.Connection") 
conn.open = "DRIVER={MySQL ODBC 3.51 Driver};"_ 
& "SERVER=localhost;"_ 
& "DATABASE=CARO1;"_ 
& "UID=root;PWD=; OPTION=16384;" 

Set Rs = conn.Execute("SELECT Bilder,storlekfarg FROM Product where Bilder != 'NULL' AND Produktnamn = 'lampa1'") 

If Rs.EOF Then 
Rs.Close : Set Rs = Nothing 
conn.Close : Set conn = Nothing
Response.Write "Inga poster än.." 
 

Else arrRecs = Rs.GetRows() 
Rs.Close : Set Rs = Nothing 
conn.Close : Set conn = Nothing 

For i = 0 To UBound(arrRecs,2)
Response.Write"<tr><td><p align=""center""><strong>Lampa 1</strong></p></td></tr>"
p(0) = arrRecs(0,i)
p(1) = arrRecs(1,i)

Response.Write"<img src= """& sokvag &"""></td><td> 
<form action=""Produkter.asp"" method=""post"" name=""produkt1"">" & _
"<table width=""150"" border=""0""> 
<tr> 
<td height=""26"" colspan=""2"">Storlek</td> 
<td>" & _
"<select name=""strl1""><option value="""& p(1) &""">"& p(1) &"</option></select>" & _
"</td> 
</tr> 

</table> 
</form>"

Next

End If
%>
 
</td> 
</tr> 
</table> 

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

</div> 
</tr> 
</table> 
</div>
```

Mvh

Permalänk: https://www.webforum.nu/p/1058947

## #10 — crisse6, 2003-05-22T21:32Z

detta da?:

```
<table width="150" border="0"> 
<tr> 
<td><table width="150" border="0"> 
<tr><td> 
<% 
Dim conn, Rs, arrRecs, i, p(1) 
Set conn = createobject("ADODB.Connection") 
conn.open = "DRIVER={MySQL ODBC 3.51 Driver};"_ 
& "SERVER=localhost;"_ 
& "DATABASE=CARO1;"_ 
& "UID=root;PWD=; OPTION=16384;" 

Set Rs = conn.Execute("SELECT Bilder,storlekfarg FROM Product where Bilder != 'NULL' AND Produktnamn = 'lampa1'") 

If Rs.EOF Then 
Rs.Close : Set Rs = Nothing 
conn.Close : Set conn = Nothing 
Response.Write "Inga poster än.." 

Else arrRecs = Rs.GetRows() 
Rs.Close : Set Rs = Nothing 
conn.Close : Set conn = Nothing 

For i = 0 To UBound(arrRecs,2) 
Response.Write"<tr><td><p align=""center""><strong>Lampa 1</strong></p></td></tr>" 
p(0) = arrRecs(0,i) 
p(1) = arrRecs(1,i) 

Response.Write	"<img src= """& sokvag &"""></td><td>"&_
		"<form action=""Produkter.asp"" method=""post"" name=""produkt1"">" & _ 
		"<table width=""150"" border=""0"">"&_
		"<tr><td height=""26"" colspan=""2"">Storlek</td>"&_
		"<td>"&_ 
		"<select name=""strl1""><option value="""& p(1) &""">"& p(1) &"</option></select>"&_ 
		"</td></tr></table></form>"
Next 
End If 
%> 
</td> 
</tr> 
</table> 
</td> 
</tr> 
</table> 
</div> 
</tr> 
</table> 
</div>
```

psst.... anvand kod-taggarna nasta gang ;)

Permalänk: https://www.webforum.nu/p/1058960

## #11 — OveRRidE, 2003-05-22T21:37Z

Runken: Nu har jag redigerat tre inlägg i den här tråden. Börja använda kod-taggarna nu. 

Nåväl, testa det här:

```
<table width="150" border="0"> 
<tr> 
<td><table width="150" border="0"> 
<tr><td>
<%
Dim conn, Rs, arrRecs, i, p(1)
Set conn = createobject("ADODB.Connection") 
conn.open = "DRIVER={MySQL ODBC 3.51 Driver};"_ 
& "SERVER=localhost;"_ 
& "DATABASE=CARO1;"_ 
& "UID=root;PWD=; OPTION=16384;" 

Set Rs = conn.Execute("SELECT Bilder,storlekfarg FROM Product where Bilder != 'NULL' AND Produktnamn = 'lampa1'") 

If Rs.EOF Then 
Rs.Close : Set Rs = Nothing 
conn.Close : Set conn = Nothing
Response.Write "Inga poster än.." 
 

Else arrRecs = Rs.GetRows() 
Rs.Close : Set Rs = Nothing 
conn.Close : Set conn = Nothing 

For i = 0 To UBound(arrRecs,2)
Response.Write"<tr><td><p align=""center""><strong>Lampa 1</strong></p></td></tr>"
p(0) = arrRecs(0,i)
p(1) = arrRecs(1,i)

Response.Write "<img src= """& sokvag &"""></td><td><form action=""Produkter.asp"" method=""post"" name=""produkt1"">" & _
"<table width=""150"" border=""0"">" & _ 
"<tr>" & _
"<td height=""26"" colspan=""2"">Storlek</td>" & _
"<td>" & _
"<select name=""strl1""><option value="""& p(1) &""">" & p(1) & "</option></select>" & _
"</td>" & _
"</tr></table></form>"

Next

End If
%>
 
</td> 
</tr> 
</table> 

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

</div> 
</tr> 
</table> 
</div>
```

Permalänk: https://www.webforum.nu/p/1058970

## #12 — Runken, 2003-05-24T17:08Z

Sorry OveRRidE, är inte så haj på ASP att jag ser vad felet är på en gång.

Tack så mycket för hjälpen Chris, nu kan jag  äntligen harva vidare...

Mvh

Permalänk: https://www.webforum.nu/p/1060452

## #13 — OveRRidE, 2003-05-24T17:38Z

> **Runken skrev:**
>
> Sorry OveRRidE, är inte så haj på ASP att jag ser vad felet är på en gång.

Nu förstår jag inte alls vad du menar. :o

Jag menade att du skall posta din kod i wF:s kod-taggar, \[ kod \] och \[ /kod \].

Permalänk: https://www.webforum.nu/p/1060463

## #14 — Runken, 2003-05-24T22:34Z

Oj, f'låt..  Visste jag inte ens om.. Har inte varit tillräckligt uppmärksam. Nu lär jag aldrig glömma. Hoppas du förstår situationen..:-)

Mvh

Permalänk: https://www.webforum.nu/p/1063431

## #15 — OveRRidE, 2003-05-24T23:46Z

> **Runken skrev:**
>
> Oj, f'låt..  Visste jag inte ens om.. Har inte varit tillräckligt uppmärksam. Nu lär jag aldrig glömma. Hoppas du förstår situationen..:-)

Så farligt är det inte. ;)

Det är bättre för alla ifall kod-taggarna används när de behövs, dock. Läs gärna igenom [Riktlinjerna för ASP-, VBScript-forumet](http://www.webforum.nu/showthread.php?s=&threadid=55116), där står det mesta.

Permalänk: https://www.webforum.nu/p/1063483

---

Tråden på webben: https://www.webforum.nu/amne/asp/77721-loopa-ut-tabeller
