Click to See Complete Forum and Search --> : ASP/VBScript - Like Statement


cinematic_jesi
08-29-2008, 09:25 AM
Hi,

I'm normally a PHP programmer.. and I'm having to do a website in ASP and I'm running in a little trouble with how to write this properly..

I'll show you what I'm trying to accomplish in PHP first then I'll give the variables I need to show up in ASP.

Here's an example of what I'm trying to do in PHP:
<?php

// Create Comment Count Function

$blogid = $row_myblogs['ID'];

$blogcount = mysql_num_rows(mysql_query("SELECT * FROM blog_comments WHERE blogid LIKE '%$blogid%'"));

?>

Okay, so I'm sure all of you are familiar with what I'm doing, its pretty simple.. now I need to do this with the following variables:

The identifier is: <%=(Videos.Fields.Item("ID").Value)%>
Where I need to get counts from: dbo.TblPepTalkVotes
And the identifier in the "counts" table is: VideoID

Can someone help? Thanks :)

marcone1973
08-30-2008, 04:25 AM
Hi,
I'm not sure if this can help you but let's try :)

<%
Dim blogid, strSQLSelect, RSSelect, arrSelect, blogcount

'This is to get the value from querystring, if you're getting it form a form use Request.Form("ID") instead

blogid = Request.Querystring("ID")


'Now let's pre-create sql string
strSQLSelect = "SELECT * FROM blog_comments WHERE blogid LIKE '%" & blogid & "%' "

'Please, note that if you only have to "count the rows" you're likely not to need all fields of db table so maybe you can just SELECT the first key-field by using "SELECT NameOfFirstFieldOnYouTable FROM blog_comments...". This will return a lighter Recordst


'Get the Recordset
Set RSSelect = YourConnectionName.Execute(strSQLSelect)

'Check if recordset is not empty
if Not RSSelect.Eof AND Not RSSelect.Bof then
arrSelect = RSSelect.Getrows 'This converts RS to a handier array
else
arrSelect = Null
end if

'We no longer need RS so free resources
RSSelect.close
Set RSSelect = Nothing

'And now the result:
if IsArray(arrSelect) then 'This mean that some rows are in the array
blogcount = UBound(arrSelect, 2)+1 '0-index arrays
else
blogcount = 0
end if

Bullschmidt
09-07-2008, 04:28 PM
And here's a simple little SQL Count sample I put together (so simple it doesn't even have a WHERE clause):

<%
' Set sql.
strSQL = "SELECT Count(*) AS RecCount FROM MyTable"

' Open rs.
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn

' Move to 1st (and probably only) rec.
objRS.MoveFirst

' Set var.
RecCount = objRS("RecCount")

' Close rs.
objRS.Close
Set objRS = Nothing
%>

There are <%= RecCount %> records.