我怎样才能从2个表,每5行中的第一个循环选择,显示从表2中1项?

问题描述 投票:0回答:1

我有一个MySQL数据库,并使用.asp的经典之作。

我想从两个表中选择,第一是产品,第二个是增加了。我想显示1add然后5个产品,然后1个附加等等,像这样。

Add1
Product1
Product2
Product3
Product4
Product5
Add2
Product6
Product7...

所以有了这个,我刚刚从两个表中选择,然后所有的广告都在第一,然后所有的产品展示。

sql = " SELECT * 
        FROM produkt,annonser 
        where produkt.publicera='true' 
            AND produkt.antal > "&nr&" 
            AND annonser.publicera='true' 
            AND annonser.antal > "&nr&" 
        order by 
            produkt.datum DESC, 
            annonser.datum DESC,
            produkt.artikel ASC, 
            annonser.artikel ASC limit 10"
set rs = conn.Execute (sql)

所以,我怎么能选择我想要的方式?任何输入赞赏,感谢。

好了,这个工程。

For i = 1 to 10
  If i mod 5 = 1 Then
     [Get the current Add and display it]
     if not rsAdds.EOF Then
        rsAdds.MoveNext()
     End If
  End If   
  if not rsProducts.EOF Then 
  [Display the Product]
  rsProducts.MoveNext()
Next

但现在我试着去循环这一切再次,我已经尝试了不同的方式来使用rs.MoveFirst,但我只得到RS.EOF或因此它不是将光标移动到第一条记录和循环再rs.buf是真实的?

所以,我想再次循环上述第一,然后循环播放,这样的事情。

For i = 1 to 10
      If i mod 5 = 1 Then
         [Get the current Add and display it]
         if not rsAdds.EOF Then
            rsAdds.MoveNext()
         End If
      End If   
      if not rsProducts.EOF Then 
      [Display the Product]
      rsProducts.MoveNext()
    Next

//Set the rs to move first so that the below will run-----

For x = 1 to 10
      If x mod 5 = 1 Then
         [Get the current Add and display it]
         if not rsAdds.EOF Then
            rsAdds.MoveNext()
         End If
      End If   
      if not rsProducts.EOF Then 
      [Display the Product]
      rsProducts.MoveNext()
    Next

那么,或如何移动RS向第一篇文章的第一循环结束后,因此它可以运行第二个代码?谢谢。

mysql sql select
1个回答
0
投票

我想通过ASP classic你的意思是实际VBA在一个文件中(或JavaScript?),没有.NET或控制。

你将不得不与程序代码和SQL的组合来做到这一点。因为它看起来像你的添加和你的产品没有涉及到对方,你应该拉他们在单独的查询。

因此,代码会是这个样子:

Dim rsAdds = [query and code to get the Adds]
Dim rsProducts = [query and code to get the Products]

' I'm not sure if you want just 10 products displayed, or all of them.  I'm going 
' I'm going to go with 10.

For i = 1 to 10
  If i mod 5 = 1 Then
     [Get the current Add and display it]
     if not rsAdds.EOF Then
        rsAdds.MoveNext()
     End If
  End If    
  [Display the Product]
  rsProducts.MoveNext()
Next i

如果你想要的仅仅是两个不相关的表内插的数据,没有什么数据实际上是,不要浪费时间试图欺骗SQL到这样做对你的关注。做程序上。

© www.soinside.com 2019 - 2024. All rights reserved.