0

In my DB (mysql) I have a table 'ads' which contains info about different ads on a website. I want to track unique clicks on any ad. So I created a field 'item_discount_userid' (mediumtext) in table ads and want to store users IDs comma separated in that field (like '1,13,44,22,45') And on click I want to check is user ID is already in that list or not. If not I want to add user ID to that list and send him mail. Else - do nothing. Can some one help me with PHP code (7.3 php)?

To be short I want something like this:

if 'user_id' is in 'item_discount_userid' 
{
}
else
{
add user_id in 'item_discount_userid';
}

Sorry for my poor English, and I am a newbee in PHP. Tried searching, tried some answers but failed. Thanks ahead!

shaedrich
  • 5,457
  • 3
  • 26
  • 42
  • Do not store the data that way. Create another table to store user-clicks. – Salman A Jun 14 '21 at 09:49
  • Can you tell me the best way to make a new table? I have ads (a,b,c,etc), and users (1,2,3,etc) I need to track only first click of any user on any ad. –  Jun 14 '21 at 09:55
  • `CREATE TABLE foo (ad_id int, user_id int, clickdate datetime, etc)`??? – Salman A Jun 14 '21 at 09:56
  • In result i will store all unique clicks in separate strings? Like ad_id 1, user_id 1 ad_id 1, user_id 2 ad_id 1, user_id 3 ad_id 2, user_id 1 ad_id 2, user_id 2 Instead of ad_id 1, user_id 1,2,3,4 ad_id 2, user_id 1,2,3,4 –  Jun 14 '21 at 09:59
  • 1
    You will not store anything as string. Store clicks as rows in database, one row represents one click, you could choose not to insert a row if there is a duplicate. You should ask a different if you want suggestions about how to design the table... comments are not for extended discussion. – Salman A Jun 14 '21 at 10:03
  • if you do by this method then lot work you will need to do, well it is possible by either ways – Shakeel Ahmad Jun 14 '21 at 10:34

0 Answers0