Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 loop help
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

GhettoDalaiLama
Junior Member

212 Posts

Posted - 26 April 2002 :  02:36:44  Show Profile  Visit GhettoDalaiLama's Homepage  Send GhettoDalaiLama an ICQ Message
I need to select a bunch of records from a MySQL DB and insert them into some HTML.

The code I'm using right now simply reads the querystring and grabs just that one record, but I need to modify it to grab everything and print it out.

The code currently stands at:

Dim strWhatPic
strWhatPic = Request.QueryString("pic")

Dim objConn
set objConn = Server.CreateObject("ADODB.Connection")

objConn.Open strConnString

Dim objRS
set objRS = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM pictures WHERE PIC_ID = " & strWhatPic

objRS.Open strSQL, objConn

strPIC_URL = objRS("PIC_URL")
strPIC_BORDER = objRS("PIC_BORDER")
strPIC_DESCRIPTION = objRS("PIC_DISCRIPTION")

%>
<img src="<% = strPIC_URL %>" border="<% = strPIC_BORDER %>" alt="<% = strPIC_DESCRIPTION %>">
<%

objRS.Close
set objRS = nothing
objConn.Close
set objConn = nothing

%>


How can I loop this so that it grabs everything from the PICTURES table and inserts it as HTML.

This is what I've come up with so far but it doesn't seem to work...


Dim strWhatPic
strWhatPic = Request.QueryString("pic")

Dim objConn
set objConn = Server.CreateObject("ADODB.Connection")

objConn.Open strConnString

Dim objRS
set objRS = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM pictures WHERE PIC_ID = " & strWhatPic

objRS.Open strSQL, objConn

strPIC_URL = objRS("PIC_URL")
strPIC_BORDER = objRS("PIC_BORDER")
strPIC_DESCRIPTION = objRS("PIC_DISCRIPTION")

strWhatPic = strWhatPic + 1
rs.MoveNext
do until strSQL.EOF = True
loop

%>


Umm... yeah... I just chopped that code together... I really didn't think it would work, but I figured it was a starting point.

Can anyone help?

Thanks.

-------------------------
http://forums.akghetto.com
OS: Win2000 Adv Server SP2
Webserver: IIS 5.0
Snitz: 3.3.03
MySQL: 3.23.40
ODBC Driver: MySQL v.2.50.37.00 - 20.Apr.01

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 26 April 2002 :  07:36:08  Show Profile
When you execute this sql statement:

strSQL = "SELECT * FROM pictures WHERE PIC_ID = " & strWhatPic

You are specifying a specific PIC_ID to grab. Hence, one record. If you want everything from the pictures tables simply use:

strSQL = "SELECT * FROM pictures"

Then use a loop like so:


do while not rs.EOF
' put whatever response.write to create the html you want
rs.movenext
loop


Nikkol

Edited by - Nikkol on 26 April 2002 07:37:57
Go to Top of Page

GhettoDalaiLama
Junior Member

212 Posts

Posted - 26 April 2002 :  14:29:55  Show Profile  Visit GhettoDalaiLama's Homepage  Send GhettoDalaiLama an ICQ Message
ok... I did


do while not objRS.EOF
Response.Write "<img src=""" & strPIC_URL & """ border=""" & strPIC_BORDER & """ alt=""" & strPIC_DESCRIPTION & """>" & vbNewLine & _
objRS.movenext
loop


however it just repeats the same result over and over....

-------------------------
http://forums.akghetto.com
OS: Win2000 Adv Server SP2
Webserver: IIS 5.0
Snitz: 3.3.03
MySQL: 3.23.40
ODBC Driver: MySQL v.2.50.37.00 - 20.Apr.01
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 26 April 2002 :  14:32:53  Show Profile
repeat on forever or just for the number of records you have?

can you post your new code?

Nikkol
Go to Top of Page

GhettoDalaiLama
Junior Member

212 Posts

Posted - 26 April 2002 :  15:07:52  Show Profile  Visit GhettoDalaiLama's Homepage  Send GhettoDalaiLama an ICQ Message
It repeats for the number of records I have....

here's the code I'm doing....



Dim objConn
set objConn = Server.CreateObject("ADODB.Connection")

objConn.Open strConnString

Dim objRS
set objRS = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM pictures"

objRS.Open strSQL, objConn

strPIC_URL = objRS("PIC_URL")
strPIC_BORDER = objRS("PIC_BORDER")
strPIC_DESCRIPTION = objRS("PIC_DISCRIPTION")

do while not objRS.EOF
Response.Write "<img src=""" & strPIC_URL & """ border=""" & strPIC_BORDER & """ alt=""" & strPIC_DESCRIPTION & """>" & vbNewLine & _
objRS.movenext
loop

objRS.Close
set objRS = nothing
objConn.Close
set objConn = nothing



-------------------------
http://forums.akghetto.com
OS: Win2000 Adv Server SP2
Webserver: IIS 5.0
Snitz: 3.3.03
MySQL: 3.23.40
ODBC Driver: MySQL v.2.50.37.00 - 20.Apr.01
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 26 April 2002 :  15:13:25  Show Profile
Make it this:


Dim objConn
set objConn = Server.CreateObject("ADODB.Connection")

objConn.Open strConnString

Dim objRS
set objRS = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM pictures"

objRS.Open strSQL, objConn

do while not objRS.EOF
strPIC_URL = objRS("PIC_URL")
strPIC_BORDER = objRS("PIC_BORDER")
strPIC_DESCRIPTION = objRS("PIC_DISCRIPTION")
Response.Write "<img src=""" & strPIC_URL & """ border=""" & strPIC_BORDER & """ alt=""" & strPIC_DESCRIPTION & """>" & vbNewLine & _
objRS.movenext
loop

objRS.Close
set objRS = nothing
objConn.Close
set objConn = nothing


Nikkol
Go to Top of Page

GhettoDalaiLama
Junior Member

212 Posts

Posted - 26 April 2002 :  15:17:06  Show Profile  Visit GhettoDalaiLama's Homepage  Send GhettoDalaiLama an ICQ Message
Works great... thanks a bunch!

-------------------------
http://forums.akghetto.com
OS: Win2000 Adv Server SP2
Webserver: IIS 5.0
Snitz: 3.3.03
MySQL: 3.23.40
ODBC Driver: MySQL v.2.50.37.00 - 20.Apr.01
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.26 seconds. Powered By: Snitz Forums 2000 Version 3.4.07