0

Hello I have a problem writing same record two time into loop cycle. I take recordset from mysql with this code:

strconn = MM_connGest_STRING
set conn = Server.CreateObject("ADODB.Connection")
Conn.Open strconn
       
SQL = "SELECT * FROM AMOR_DOC JOIN AMOR_REGIONI ON AMOR_REGIONI.ID_REG = AMOR_DOC.REGIONE WHERE REGIONE = '"&Request.QueryString("REGIONE")&"' ORDER BY TIPO ASC" 
Set regionali = conn.Execute(SQL)

and then I would loop result so:

<% while not regionali.EOF %>
  <h4 class="list-group-item-heading"><%=(regionali("NOME"))%></h4>
  <p class="list-group-item-text"><% if regionali("ZONE") <> "" then%><span><b>Zone:</b> <%=regionali("ZONE")%><br><% end if %></p>
  <% regionali.movenext()
wend %>

But the problem is that if I write two time same value, for example regionali("ZONE"), it show me only one time! Where is my problem?

user692942
  • 16,398
  • 7
  • 76
  • 175
DigitalXP
  • 179
  • 5
  • 18
  • 1
    Try: (1). Specify the fields to be selected in the sql query instead of select * (2). Assign the required values from the recordset to variables and reuse (3) Use regionali.Collect("ZONE") instead of regionali("ZONE"). – Flakes Feb 21 '22 at 10:15
  • (3). Don't inject values directly from the query string into the SQL statement instead use an `ADODB.Command` object to [build a parameterised query](https://stackoverflow.com/a/20702205/692942). What you are doing is vulnerable to a [SQL Injection](https://en.wikipedia.org/wiki/SQL_injection). – user692942 Feb 21 '22 at 10:22
  • @Flakes what is `regionali.Collect("...")`? Never heard of that [method of the `ADODB.Recordset`](https://learn.microsoft.com/en-us/sql/ado/reference/ado-api/recordset-object-properties-methods-and-events?view=sql-server-ver15) before? I was with you up until point 3. – user692942 Feb 21 '22 at 10:25
  • If you want to repeat the same record, don't call `regionali.movenext()` it's as simple as that. Not sure why though... You could control the number of times you want each record in the loop to repeat using a [`For` statement](https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/scripting-articles/sa3hh43e(v=vs.84)). – user692942 Feb 21 '22 at 10:28
  • 1
    @user692942 See: https://stackoverflow.com/a/16735587/1682881 – Flakes Feb 21 '22 at 11:13
  • @Flakes learn something new, never heard of it never needed it and I've been using ADODB for 20+ years. – user692942 Feb 21 '22 at 11:36

0 Answers0