Web Wiz - Solar Powered Eco Web Hosting

  New Posts New Posts RSS Feed - VBScript - General - Question - Duplicate fields i
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

VBScript - General - Question - Duplicate fields i

 Post Reply Post Reply
Author
luwandui View Drop Down
Groupie
Groupie


Joined: 10 August 2011
Status: Offline
Points: 64
Post Options Post Options   Thanks (0) Thanks(0)   Quote luwandui Quote  Post ReplyReply Direct Link To This Post Topic: VBScript - General - Question - Duplicate fields i
    Posted: 02 September 2011 at 8:04am
I have a field objrs("title") and it loops through the database to list all of the titles. Let's say for the sake of this example, there are 10 titles.

If there is a DUPLICATE title, I want to make the font color red, all others in black. So if 2 titles are the same, those 2 titles will be listed in red; the other 8 in black.

I can't seem to figure out the appropiate if/then statement that does that. I tried if objrs("title") > 1, but that doesn't work. I tried if objrs ("title") = objrs ("title"); that doesn't work.

Any suggestions would be appreicated.

Thanks
Back to Top
yandr View Drop Down
Groupie
Groupie


Joined: 10 March 2009
Status: Offline
Points: 106
Post Options Post Options   Thanks (0) Thanks(0)   Quote yandr Quote  Post ReplyReply Direct Link To This Post Posted: 02 September 2011 at 1:33pm
It is not exactly what you are looking for, but you wish to display just the duplicate titles you can

Select title
from your_table
group by title
having count(id) > 1

You can also use (but I haven't personally tried it)

select c1.id, c2.id, c1.title
from your_table c1, your_table c2
where c1.id < c2.id and c1.title = c2.title
Back to Top
s93ncer View Drop Down
Newbie
Newbie


Joined: 08 February 2006
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote s93ncer Quote  Post ReplyReply Direct Link To This Post Posted: 17 April 2012 at 8:31am
If it's only on the screen you want to highlight duplicates you would need to do something like this

sql = "select title, author, price from books"
rs.open sql, dbConn
if not rs.eof then alldata = rs.getrows()
rs.close

if isarray(alldata) then

for loop = 0 to ubound(alldata,2)
'check if item has a duplicate first
    for secondloop = 0 to ubound(alldata,2)
    if alldata(0,loop) = alldata(0,secondloop) and loop <> secondloop then 
'this makes sure you are not comparing the same row^^^^^^
        response.write("<font color='red'>")
            exit for
        end if                 
    next
    response.write(alldata(0,loop) & " - " & alldata(1,loop) & " - " & alldata(2,loop) & "<br>")
next
end if
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.07
Copyright ©2001-2024 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Policy

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2024 Web Wiz Ltd. All rights reserved.