Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSTR problem

Status
Not open for further replies.

PhatH

IS-IT--Management
Mar 30, 2004
88
US
Hello all,

I have a sql:
<input type="checkbox" value=<% =rsPro("ProdNum") %> name="productid" <% if inStr(productid,trim(rsPro("ProdNum"))) then response.write ("Checked") %>><% =rsPro("ProdName") %>

my intension is to get product name box checked if the product number matches with one of the numbers in a string that contain more than one product number such as: 1, 2, 3, ....

I was doing ok with the product numbers that smaller than 10.
The PROBLEM:
If my productid string has product number 12 for instance, the code will check prodNum box 1, 2, and 12 because all of these number are INSTR.

Is there a way to specify the INSTR code to a specific #?
Thanks!
 
Simple trick: use "-1-2-3-4-", then search w/ InStr() for "-" & productNumber & "-".
 
to save it in "-1-2-3-4-"???

thing is... when a software is added into a database, it can be the software for more than 1 product. Therefore, I had products' checkboxes so that user can check to the boxes that applied to the software added. After saved, the column in table will display, for instance 1, 2, 3,... , automatically. I have no control over it. :)
 
No... leave database as it is, use -1-2-3- only to get instr() working properly (in temp variable).
 
Is this how I should do:

<input type="checkbox" value=<% =rsPro("ProdNum") %> name="productid" <% if inStr(productid,"-"&rsPro("ProdNum")&"-") then response.write ("Checked") %>><% =rsPro("ProdName") %>

The code doesn't check the boxes as if it doesn't see any match.
 
First convert productID into -1-2-3- format. For example, if it was in "1, 2, 3" format this should work:

blah = "-" & replace(replace( productID, " ", "" ), ",", "-") & "-"

Do this only once, outside of loop that displays checboxes. Then:

<input type="checkbox" value=<% =rsPro("ProdNum") %> name="productid" <% if inStr(blah,"-"& rsPro("ProdNum")&"-") > 0 then response.write ("Checked") %>><% =rsPro("ProdName") %>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top