Jump to content

Best method of incorporating a flagging system?


Modernvox

Recommended Posts

Just your thoughts on creating a flagging system where we set up a cron to automatically delete rows with x amounts of flags.

 

What would be the best route to take?

 

Add a hidden form field?

Use an embedded link that users may press to add 1 to the flags row?

 

I'm a little overwhelmed with the starting point....

Link to comment
Share on other sites

There are two routes you can go down, either adding another field to the table you current have, or creating a new table specifically for storing 'flags'.

 

Considering you only want to know if there are 5 flags, and not extra info like date/time submission of flag, who flagged it up, their reason etc, I'd go with the extra field option.

 

So:

 

1)  Add another field to your current table called 'flags'

2)  Set up your page so that the user can add 1 to this flag field, you might want to use sessions/cookies to prevent multiple submissions - though if you're afraid of abuse you may wish to go with the 2nd option I suggested above

3)  Create a script (which the CRON will call) that does a query on all rows which have a 'flag' value of 5 or more, and delete them

 

 

The second option will be a bit more complex, if the above isn't what you were looking for I can go in to more detail.

Link to comment
Share on other sites

There are two routes you can go down, either adding another field to the table you current have, or creating a new table specifically for storing 'flags'.

 

Considering you only want to know if there are 5 flags, and not extra info like date/time submission of flag, who flagged it up, their reason etc, I'd go with the extra field option.

 

So:

 

1)  Add another field to your current table called 'flags'

2)  Set up your page so that the user can add 1 to this flag field, you might want to use sessions/cookies to prevent multiple submissions - though if you're afraid of abuse you may wish to go with the 2nd option I suggested above

3)  Create a script (which the CRON will call) that does a query on all rows which have a 'flag' value of 5 or more, and delete them

 

 

The second option will be a bit more complex, if the above isn't what you were looking for I can go in to more detail.

 

Hi Monkeh and thanks for the reply supply and support.

I think the second would be better as far as security is concerned.

 

I would like to only allow logged in users to flag, so i guess I won't need to save ip's?

I would like just 1 flag allowed per user along with the reason they are flagging from a preselected list like maybe:

1. Venue doesn't exist

2. Venue no longer hiring bands

3. Wrong genre listed

etc...

 

Should be fairly simple I am assuming?

Link to comment
Share on other sites

Alright well you'll need to do a bit more work for the second option, but here's the rough outline:

 

1)  Create a new 'flags' table with the fields: id, venueId, userId, reason

 

I hope your venues table has an ID field as you'll need something to uniquely identify it.

 

2)  Set up your page to allow visitors to flag up a venue and specify which reason

 

3)  Do some checking once the user has submitted the flag:  do a query on the venueId, and current user's ID, and make sure that there isn't a row in the 'flags' table containing both.  If the check passes, then submit the flag to the table and you're done (this handles re-submissions from the same user for the same venue).

 

4)  As for your CRON script, you'll probably need to use a JOIN if you want to do it pure MySQL (and I must admit I'm hopeless with JOINs).  Or if you wanted to do it with some PHP:

 

$query = "SELECT id, COUNT(*) FROM `flags` GROUP BY `id`";

 

Loop through that query, check whether COUNT(*) is greater than or equal to 5 and then perform another query to delete the row.

 

 

 

Not going to write the code for you, but that should at least get you on the right track.

Link to comment
Share on other sites

Alright well you'll need to do a bit more work for the second option, but here's the rough outline:

 

1)  Create a new 'flags' table with the fields: id, venueId, userId, reason

 

I hope your venues table has an ID field as you'll need something to uniquely identify it.

 

2)  Set up your page to allow visitors to flag up a venue and specify which reason

 

3)  Do some checking once the user has submitted the flag:  do a query on the venueId, and current user's ID, and make sure that there isn't a row in the 'flags' table containing both.  If the check passes, then submit the flag to the table and you're done (this handles re-submissions from the same user for the same venue).

 

4)  As for your CRON script, you'll probably need to use a JOIN if you want to do it pure MySQL (and I must admit I'm hopeless with JOINs).  Or if you wanted to do it with some PHP:

 

$query = "SELECT id, COUNT(*) FROM `flags` GROUP BY `id`";

 

Loop through that query, check whether COUNT(*) is greater than or equal to 5 and then perform another query to delete the row.

 

 

 

Not going to write the code for you, but that should at least get you on the right track.

 

Excellent Monkeh, Thanks a bunch! That's plenty and will guide me in my journeys. Will report back when all is said and done in working order ::)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.