Web Wiz
Home
Home
Hosting Services
Hosting Services
Knowledgebase
Knowledgebase
Community and Support Forums
Support Forums
Customer Login
Customer Login

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

Web Wiz Web Hosting 30 Day Free Trial

Windows Hosting 30 Day Free Trial, with no obligation, on all our Windows Web and Reseller Hosting Packages.

For moreĀ informationĀ see our Windows Hosting 30 Day Free Trial page.

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: 94
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: 4
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
  Share Topic   

Forum Jump Forum Permissions View Drop Down



Become a Fan on Facebook Follow us on Twitter Web Wiz on Google+ Community Forums Web Wiz Blogs Web Wiz News
Company Information | Contact Web Wiz | Terms & Conditions | Privacy Policy

Prices exclude VAT unless otherwise stated - $, € prices shown as a guideline only
Web Wiz Ltd, Unit 10E Dawkins Road Ind. Est, Poole, Dorset, UK, BH15 4JD
Copyright ©2001-2012 Web Wiz - All rights reserved