Forums

This topic is locked

access database:display counted table

Posted 13 Jan 2003 08:49:48
1
has voted
13 Jan 2003 08:49:48 zoe z posted:
hi everyone...
this is what i want my database to do: count how many user that have registered for a certain product and display it in the system.so, everytime a user pick a certain product to register,the database automatically count him,and display,say "3 users registered for this product".and,can i limit how many users can register for a product?say,only 4 users can register for a product and when the 5th user try to register,he will be denied.i have 2 tables and they look like this:
tblRegister||Prod_ID|user_ID|date|time tblProduct||Prod_ID|prod_name|prod_desc|no_of_register
so,how can i possibly do this the right way?
pls,can anybody help..


Replies

Replied 13 Jan 2003 11:07:15
13 Jan 2003 11:07:15 Julio Taylor replied:
1) To count and display the current registrations:
<pre id=code><font face=courier size=2 id=code>
SELECT prod_id as Product, COUNT(user_id) as Users
FROM tblRegister
GROUP BY user_id
</font id=code></pre id=code>

This will return something like this

<pre id=code><font face=courier size=2 id=code>
Product Users
------------------------------------------------
Product_1 3
Product_2 1
</font id=code></pre id=code>

You can add &lt;WHERE&gt; clauses to the query to filter the results for certain products only etc...

2) To deny access to users, you will need to tell me what language you are using. The best way i can think of doing this is to set up a check function when the user enters the "Register" page, which will work something like this (in loose syntax)

<pre id=code><font face=courier size=2 id=code>
variable_check = count(users) from tblRegister where product = [GET_VAR = prod_id]

if variable_check &gt; 4 (or any other number you want to limit it to) then
print ("too many users have registered for this product" or something like that
else
&lt;insert record&gt;
</font id=code></pre id=code>

sorry about the vague code, but it should give you a general idea. If you're using ASP you'll be better off asking over at the ASP forums and so forth.

Let me know if you need more help.... <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>

------------------------
Julio

PHP | MySQL | UD4

ICQ: 19735247

Edited by - poolio on 13 Jan 2003 11:12:36
Replied 14 Jan 2003 05:10:15
14 Jan 2003 05:10:15 zoe z replied:
ok poolio,thanx.i'll try that.i've also posted this same question in the asp forum just in case someone can help me with the asp coding
<img src=../images/dmxzone/forum/icon_smile_blush.gif border=0 align=middle>

Reply to this topic