...

View Full Version : Max entires HELP??



csandbach
08-18-2007, 12:00 AM
Hi,

I dont know if this is possible, and i know to some it's a little crude what i want to do, but im still learning so bare with me.

What im aiming to do is limit the ammount of entries a user can put in, the way i want to do it is set a max by using assigning it in the login session which is how i send the account id page to page.


SELECT data yada yada yada from table where id=12example

if result count = > "5[provided by session]" then response.write" no more allowed"
else response.write "click here to add more"

How do i get the page to count the number of results found based on the query and if it is more than > the number in the session data give an error, i know it shold look similar but i have no experience with restricting queries.

any guidance appreciated.

does any of this make sense?

Chris.

westmatrix99
08-18-2007, 08:21 AM
This code you put right at the top of your sibmission page.

<%
Dim postlimit, total
postlimit = 2 'your lmit that you want
total = (rsLimit_total) 'your recordset total
If total => postlimit then
Response.redirect "error.asp"
End If
%>
Have fun.

csandbach
08-18-2007, 10:09 AM
I have done the following

<%
Dim postlimit, total
postlimit = 2 'your lmit that you want
Set rsLimit = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT [id] FROM table WHERE strGroup ='bob"
rsLimit.Open strSQL, adoCon
total = (rsLimit_total) 'your recordset total
If total => postlimit then
Response.redirect "error.asp"
End If
%>

It does not work, however if i change the vaule to 0 it goes to error.asp, any ideas??

westmatrix99
08-18-2007, 10:38 AM
Changing the code to that, makes no sense now.

You have the code on top of page:


<%
Dim postlimit, total
postlimit = 2 'your lmit that you want
total = (rs_recordset_total) 'your recordset total
If total => postlimit then
Response.redirect "error.asp"
End If
%>

You have your recordset and your recordset name is what you need above.

<%
Set rs_recordset= Server.CreateObject("ADODB.Recordset")
rs_recordset.ActiveConnection = conn_STRING
rs_recordset.Source = "SELECT * FROM table"
rs_recordset.CursorType = 0
rs_recordset.CursorLocation = 2
rs_recordset.LockType = 1
rs_recordset.Open()
%>

Make sense?

westmatrix99
08-18-2007, 10:47 AM
Post your "select query" not the entire page.

csandbach
08-18-2007, 10:54 AM
Hmm, not really, i open the db connection by using an include in the top of the page:

<<inside include file>>

Set adoCon = Server.CreateObject("ADODB.Connection")

src = Server.MapPath("/users.mdb")
sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & src
adoCon.Open sConnStr

<<end>>

Sorry if i appear dumb, im still learning.

westmatrix99
08-18-2007, 10:58 AM
Ok so you have this:

<?'connection.php'?>
Then
<? The select statement is what I need ?>
Then whatever stuff you need
Then
<?Close connection?>
Post the select statement.

csandbach
08-18-2007, 11:00 AM
"SELECT * FROM posts WHERE strGroup ='bob'" strgroup contains the username

westmatrix99
08-18-2007, 11:03 AM
OK, Please Post the entire page that you need this to work on.

csandbach
08-18-2007, 11:08 AM
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="includes/dbconn.inc"--> Which is contains the above

<%
Dim postlimit, total
postlimit = 2 'your lmit that you want
Set rsLimit = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM posts WHERE strGroup ='bob'" << this is where i need it to give me the total number of posts from "BOB"
rsLimit.Open strSQL, adoCon
total = (rsLimit_total) 'your recordset total
If total => postlimit then
Response.redirect "error.asp"
End If
%>

The rest of the page will be a form that allows the user to submit another entry if they have 2 or less posts.

Confused?

westmatrix99
08-18-2007, 11:15 AM
Try this, with your recordset name which is "strSQL"


<%
Dim postlimit, total
postlimit = 2 'your lmit that you want
total = (strSQL_total) 'your recordset total
If total => postlimit then
Response.redirect "error.asp"
End If
%>
<%
strSQL = "SELECT * FROM posts WHERE strGroup = 'bob'"
rsLimit.Open strSQL, adoCon
'strSQL_total should be your total records for that user or select statement.
%>

westmatrix99
08-18-2007, 11:23 AM
Working?
Yes or No would do.

csandbach
08-18-2007, 11:25 AM
No joy,

I thought i needed to give the recordset a name

if i run the code you said it comes back with

Object required: 'rsLimit'

If i change it to
<%
Dim postlimit, total
postlimit = 1 'your lmit that you want
total = (rsLimit_total) 'your recordset total
If total => postlimit then
Response.redirect "error.asp"
End If
%>

<%
Set rsLimit = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM posts WHERE strGroup = 'bob'"
rsLimit.Open strSQL, adoCon
'strSQL_total should be your total records.
%>

it works it just does not work with the > more than unless i set it to 0 i read somewhere something about recordsets resulting in -1 or something.

the table looks like

date entry strGroup
03/03/03 My name is bob bob
04/03/03 hello again test bob

Do i need to loop through them or something?

westmatrix99
08-18-2007, 11:30 AM
Copy and paste the code I added your'e code seems wrong.

You are using Capital letters instead of Dimmed letters which are small letters.

Look at the code I posted use that first then come back and say YAY or NAY.

csandbach
08-18-2007, 11:35 AM
Nay:(

westmatrix99
08-18-2007, 11:37 AM
Post the entire page, include everything.

westmatrix99
08-18-2007, 11:41 AM
Go here start from scratch:
http://www.webthang.co.uk/tuts/tuts_dmx/dan2/dan2_1.asp

This will help you more.

westmatrix99
08-18-2007, 11:59 AM
Any luck?

csandbach
08-18-2007, 12:47 PM
No, I must be doing something wrong, im going to start from scratch using that tutorial again.

Thanks for your help.

Chris.

westmatrix99
08-18-2007, 01:39 PM
Cool no problem.

csandbach
08-18-2007, 03:27 PM
Sorted it now, it was the -1 problem, i found a way of doing it and it works perfectly.

Again, thank you!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum