[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

grab first 4 characters of string

Hi.  Ok, so I have displayed:

[Checkbox] Team 1.jpg (id#: 1)
[Checkbox] Individual 1.jpg (id#: 2)
[Checkbox] Action 1.jpg (id#: 3)

The user chooses 2 of the following 3 selections and clicks Next to go to the next page.  What gets passed to the next page is the id#.  BUT I want him to choose only the 2 files which start with "team" and "indi".  If they don't choose those options, it goes back with an error.  So let's say he chooses id #1 and id #3, what would get passed to the next page is 1,3.  I figured that I would then query for the name of the image, then grab the first 4 characters of the name.  If the result is not "team" or "indi", then throw back the error.  Not sure how to do this though.  Any ideas?
0
COwebmaster
Asked:
COwebmaster
  • 6
  • 3
1 Solution
 
Renante EnteraCommented:
Hi COwebmaster!

Assuming that your database is MSSQL.  So, I think this is what you are looking for :
--------------
NEXT PAGE
--------------
<cfquery name="qGetRecord" datasource="#REQUEST.Datasource#">
  SELECT imageId, imageName
  FROM tblImage
  WHERE imageId IN ('#FORM.checkbox#')
  AND
  (
    LEFT(imageName, 4) = 'team' OR LEFT(imageName, 4) = 'indi'
  )
</cfquery>

<cfif qGetRecord.recordcount LT ListLen(Form.checkbox)>
  <cfoutput>
    <b>ERROR FOUND</b><br>
    Be sure that the file you have selected starts with 'team' or 'indi'<br>
    <input type="button" name="backButton" value="Back" onclick="history.back()">
  </cfoutput>
</cfif>

*Note : On the query, the LEFT() function is a database function not coldfusion.  Then for another workaround, you can also use any of these :
  a.  SUBSTRING(imageName, 1, 4)
  b.  CAST(imagename as varchar(4))

I hope that this helps you.  Just try it.


Goodluck!
eNTRANCE2002 :-)
0
 
COwebmasterAuthor Commented:
Hello eNTRANCE2002!  Let me check it out..
0
 
COwebmasterAuthor Commented:
I'm getting an error saying "Element CHECKBOX is undefined in FORM"
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
COwebmasterAuthor Commented:
Ok, I realized that I wasn't calling out the name of the checkbox.  Anyway, now I have another error:

[Macromedia][SQLServer JDBC Driver][SQLServer]Syntax error converting the varchar value &apos;1855,1856&apos; to a column of data type int.

0
 
Renante EnteraCommented:
Hmmm... :-?

Maybe, this part has the problem :
  WHERE imageId IN ('#FORM.checkbox#')

Try to change it with this :
  <!--- Just remove single quote --->
  WHERE imageId IN (#FORM.checkbox#)

I hope that this makes sense.


Regards!
eNTRANCE2002 :-)
0
 
COwebmasterAuthor Commented:
Worked, thanks!
0
 
COwebmasterAuthor Commented:
Final:


<cfquery name="qGetRecord" datasource="#REQUEST.Datasource#">
  SELECT imageId, imageName
  FROM tblImage
  WHERE imageId IN (#checkbox#)
  AND
  (
    LEFT(imageName, 4) = 'team' OR LEFT(imageName, 4) = 'indi'
  )
</cfquery>

<cfif qGetRecord.recordcount LT ListLen(checkbox)>
  <cfoutput>
    <b>ERROR FOUND</b><br>
    Be sure that the file you have selected starts with 'team' or 'indi'<br>
    <input type="button" name="backButton" value="Back" onclick="history.back()">
  </cfoutput>
</cfif>
0
 
Renante EnteraCommented:
Hi COwebmaster!

I'm glad that I have helped you.  Hope to help you again.

BTW, thanks for the points and the grade.


Best regards!
eNTRANCE2002 :-0
0
 
COwebmasterAuthor Commented:
Thanks again entrance2002!  I just posted another cfm question.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now