Re: Can not divide in ASP!
Do you set a default value for found_rows?
Presumably you want to set it to 0 before the If.
Re: Can not divide in ASP!
Yup, the default for found_rows is zero.
What is interesting is this works:
VB Code:
if rstFound.bof = false then found_rows = rstFound.Fields("foundrows").value
rstFound.Close
found_rows=44
page_count = found_rows / 2
%>Found <%=page_count%>
and prints Found 22 on the page
however this
VB Code:
if rstFound.bof = false then found_rows = rstFound.Fields("foundrows").value
rstFound.Close
page_count = found_rows
%>Found <%=page_count%>
prints Found 44 inidicating that found_rows is 44? but does not work with the divide by 2, but if I manually set it to 44 (top example) then this works????
Re: Can not divide in ASP!
Fixed it! What a load of rubbish, only took me two hours
VB Code:
<%
...
if rstFound.bof = false then found_rows = cint(rstFound.Fields("foundrows").value)
rstFound.Close
page_count = found_rows / 2
%>Found <%=page_count%>
cint was the secret - god knows why
Re: Can not divide in ASP!
Presumably because the field foundrows is a String (or Text/Char) data type, rather than a numeric type.
As you have the answer, could you please do us a little favour, and mark this thread as Resolved?
(this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)
You can do this by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved".
Re: Can not divide in ASP!
Thats what I thought - originally I was trying to use Val() but this is not supported in ASP.
However Cint does not do string to integer conversions, it converts a numeric expression to an integer.
(see http://psacake.com/web/functions.asp?id=5)
Re: Can not divide in ASP!
Quote:
Originally Posted by Rick H
However Cint does not do string to integer conversions, it converts a numeric expression to an integer.
A string is a type of expression. A string such as "234" is a numeric one ;)
The following is perfectly valid in VB, and according to Microsoft should be exactly the same for VBScript (which is what ASP uses):
Have you checked what data type the "foundrows" field is?
Re: Can not divide in ASP!
If you're ever unsure about what type of variable you're pulling back from things then you can try using typename to help you out, so:
msgbox Typename(found_rows)
in this case.
Re: Can not divide in ASP!
I'm not sure of the type as its returned by
Set rstFound = objConn.Execute("SELECT FOUND_ROWS() as foundrows")
after doing a "SELECT SQL_CALC_FOUND_ROWS ...." MYSQL query
Re: Can not divide in ASP!
Thanks l12ngo, I'll try that