Leverkusen Posted February 6, 2014 Author Share Posted February 6, 2014 (edited) <?php $postLimit = 2; // upis para if($_POST['tim1']!="" and $_POST['tim2']!="" and $_POST['tip']!="" and $_POST['kvota']!="" and $_POST['link']!="") { $ip = $_SERVER['REMOTE_ADDR']; $tim1 = str_ireplace(array("\"", "'", ""),"", $_POST['tim1']); $tim2 = str_ireplace(array("\"", "'", ""),"", $_POST['tim2']); $tim1 = ucwords(strtolower($tim1)); $tim2 = ucwords(strtolower($tim2)); $tip = str_ireplace(array("\"", "'",""),"", $_POST['tip']); $kvota = str_ireplace(array(","), ".",$_POST['kvota']); $link = str_ireplace(" ", "", $_POST['link']); $prvoslovo = str_ireplace("http://www.flashscore.com/","#", $link); $linkDozvola = ($prvoslovo[0]=="#"); if(!$linkDozvola) { echo "alert('Your link is bad! Copy the link from www.flashscore.com!')"; } else if($kvota<1.01and $kvota>99.99) { echo "alert('Kvota vam nije u opsegu od 1.01 do 99.99 .')"; } else { $racun = $_SESSION['liga_user_id']; $query = "SELECT cnr.klikovi, COUNT(cnr.id) AS post_count FROM clanovi_njihovi_racuni AS cnr LEFT JOIN clanovi_njihovi_parovi AS cnp ON cnr.id = cnp.racun AND cnp.datum=curdate() WHERE cnr.id='$racun' GROUP BY cnr.id"; $result = mysql_query($query) or die("Query: {$query}<br>Error: " . mysql_error()); $row = mysql_result($result); $klikovi = $row['klikovi']; $postCount = $row['post_count']; if($klikovi<3) { echo "<script>alert('You dont have enough Clicks for posting a game.3 Clicks is a minimum')</script>"; } elseif($postCount >= $postLimit) { //Limit met echo "You met max post count for today"; } else { $query = "INSERT INTO clanovi_njihovi_parovi SET racun='$racun', ip='$ip', datum=curdate(), vrijeme=curtime(), tim1='$tim1', tim2='$tim2', tip='$tip', kvota='$kvota',link='$link'"; $result = mysql_query($query) or die("Query: {$query}<br>Error: " . mysql_error()); $query = "UPDATE clanovi_njihovi_racuni SET klikovi = klikovi-0 WHERE id='$racun'"; $result = mysql_query($query) or die("Query: {$query}<br>Error: " . mysql_error()); echo "alert('Your Game Post is accepted')"; } } } ?> there i made echoes on english language! Edited February 6, 2014 by Leverkusen Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1467899 Share on other sites More sharing options...
jazzman1 Posted February 6, 2014 Share Posted February 6, 2014 (edited) So, this query SELECT cnr.klikovi, COUNT(cnr.id) AS post_count FROM clanovi_njihovi_racuni AS cnr LEFT JOIN clanovi_njihovi_parovi AS cnp ON cnr.id = cnp.racun AND cnp.datum=curdate() WHERE cnr.id='$racun' GROUP BY cnr.id does not give you an answer of currently its unlimited, i want to limit to 1 post per day. the user must wait until 00:00 to post again Why are you using fields of type varchar to store the date and datetime value? This insert statement should be inserted null values using mysql datatime functions on columns with type different from date and datetime. $query = "INSERT INTO clanovi_njihovi_parovi SET racun='$racun', ip='$ip', datum=curdate(), vrijeme=curtime(), tim1='$tim1', tim2='$tim2', tip='$tip', kvota='$kvota',link='$link'"; According screenshots "datum" and "vrijeme" are on varchar type in your table. You left too much mess here Edited February 6, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1467904 Share on other sites More sharing options...
Leverkusen Posted February 6, 2014 Author Share Posted February 6, 2014 (edited) wow big mistake i changed datum varchar to 'date' and time varchar to 'time; because i do them sepparately http://prntscr.com/2pxvs0 and should i change Null to 'Yes' in the table? when i do SELECT cnr.klikovi, COUNT(cnr.id) AS post_count FROM clanovi_njihovi_racuni AS cnr LEFT JOIN clanovi_njihovi_parovi AS cnp ON cnr.id = cnp.racun AND cnp.datum=curdate() WHERE cnr.id='$racun' GROUP BY cnr.id its saying "MySQL returned an empty result set (i.e. zero rows)." Edited February 6, 2014 by Leverkusen Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1467906 Share on other sites More sharing options...
jazzman1 Posted February 7, 2014 Share Posted February 7, 2014 I'm not really sure from where to start but, I do believe you should have to learn the basics of SQL and PHP. Also, as Psyco said above, when you ask for a free-paid help, you must provide all relevant information to help us help you. Not to mention that you have searched for a solution to your problem before asking it, haven't you?However, if you're trying to communicate on an English-language forum, you owe it to yourself to make an effort to write/describe the context and comments of your code at least reasonably correct English. I am Bulgarian and understand when reading Serbian language but most of the "staff" and members here do not so, they don't pay attention about your posting just scrool down the page in fine it's absolutely unuseful for anybody here. I dislike when people posting links out, for instance how to ask questions in a smart way or something similar, but do some google research and maybe you'll find some useful article for you. So, to answer your question, first, you need to define and explain in English what your intent is!If I understand correctly ( correct me if I am wrong), you have a website, where the members post links, text, pictures or something else. So, you want to restrict postings in time one per day (24 hours) for those members having postings less than 3.For those ones which already had more than 3 this restriction shouldn't work, right?Or...a second scenario.All users can make postings but only those who already had 3 clicks (as "like", "good", "yes" or something else) in their profile only they would be able to make posting more than 1 post per day.Can you explain that in a better way? Could you also explain the logic of this UPDATE statement too -> "UPDATE clanovi_njihovi_racuni SET klikovi = klikovi-0 WHERE id='$racun'"; especially the part of a SET statement - klikovi = klikovi-0. How is data represented in "klikovi" column as 0 (zero) and 1 (one) for click, or...? Why the foreign key named "racuni" is on type varchar in case, it links to PK of int type column?And finally if every click is represented as integer (0 and 1) in its column, you can simply summarize them using a sql sum() function, join both tables on "racuni" key, group them by user_ID and use the logic provided by kicken. Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1468054 Share on other sites More sharing options...
Psycho Posted February 7, 2014 Share Posted February 7, 2014 (edited) When you get zero results from that query, what ID are you using for $racun? If you run the other query I provided in reply #23 (my god has it been that many) the results will show you exactly how many records that person has in the clanovi_njihovi_parovi table total and for the current day. based upon your logic, the person must have at least three records for the current day - else you get that error message. So, on the day that you ran that query you should get that error message for ALL IDs except for ID 106 - because that one had at least three record for the current day. Edited February 7, 2014 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1468084 Share on other sites More sharing options...
Leverkusen Posted February 8, 2014 Author Share Posted February 8, 2014 I will expain from the beginning best as i can Members on my site are posting 'home team' 'away team' 'tip' odd' and 'link' and they can do it unlimited times I want to limit those posting per day to any number i want, so when i want to be limit 2 i change the number in script to 2 NO. Or...a second scenario.All users can make postings but only those who already had 3 clicks (as "like", "good", "yes" or something else) in their profile only they would be able to make posting more than 1 post per day. here was my bad Psycho, for ID 1 is showing this results http://prntscr.com/2qgx3e and other query is showing this result http://prntscr.com/2qgxoa both queries work fine, but something is wrong in the script. $query = "UPDATE clanovi_njihovi_racuni SET klikovi = klikovi-0 WHERE id='$racun'"; this was supposed to reduce ferreral clicks after each post, but i made it not to reduce. based upon your logic, the person must have at least three records for the current day - else you get that error message. This is wrong, the person can post it to 3, when he reaches that limit then he has to receive error message "You met max post count for today" So, on the day that you ran that query you should get that error message for ALL IDs except for ID 106 - because that one had at least three record for the current day. This is totaly on the contrary, they need to be approved to post all the time until they dont reach post limit of 3 When they reach post limit, they should get error message "You met max post count for today, wait for tomorrow' Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1468137 Share on other sites More sharing options...
jazzman1 Posted February 8, 2014 Share Posted February 8, 2014 So, on the day that you ran that query you should get that error message for ALL IDs except for ID 106 - because that one had at least three record for the current day. Why? According the screenshot I see 7 returned rows for each group of ID. So, the result of using mysql_num_rows should be only 1 for each of them. He could get the result of klikovi (clicks) to compare how many clicks already had for this particular group of IDs. Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1468147 Share on other sites More sharing options...
Leverkusen Posted February 10, 2014 Author Share Posted February 10, 2014 bump Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1468421 Share on other sites More sharing options...
jazzman1 Posted February 14, 2014 Share Posted February 14, 2014 To retrieve all records made per day based on the username, the query would be similar to this: select * from db_name.tbl_name where (tbl_name.date_record >= current_date() - 1 day) and tbl_name.user_name = 'some username' Then, use mysql_num_rows() and count how many rows this particular user already had . Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1468819 Share on other sites More sharing options...
jazzman1 Posted February 14, 2014 Share Posted February 14, 2014 Amend tbl_name.date_record >= current_date() - interval 1 day Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1468830 Share on other sites More sharing options...
Leverkusen Posted June 4, 2015 Author Share Posted June 4, 2015 The code looks like this know and i still have the same problem. :/ http://paste2.org/KHkb7FLY Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1513170 Share on other sites More sharing options...
Leverkusen Posted June 7, 2015 Author Share Posted June 7, 2015 bump Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1513423 Share on other sites More sharing options...
QuickOldCar Posted June 8, 2015 Share Posted June 8, 2015 jazzman1 answered what do do in response #34 and correction in #35 Nowhere in your code do you attempt to make a query and check if a user already posted that day. select * from db_name.tbl_name where (tbl_name.date_record >= current_date() - interval 1 day) and tbl_name.user_name = 'some username' Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1513433 Share on other sites More sharing options...
Leverkusen Posted June 10, 2015 Author Share Posted June 10, 2015 Code looks like this now, bolded things are added but still i can post when i want. <?php // upis para if($_POST['tim1']!="" and $_POST['tim2']!="" and $_POST['mtime']!="" and $_POST['tip']!="" and $_POST['kvota']!="" and $_POST['ulog']!="" and $_POST['link']!=""){ $racun=$_SESSION['liga_user_id']; $result = mysql_query("select * from clanovi_njihovi_racuni where id='$racun';"); $row = mysql_fetch_array($result); $profit = $row['profit']; $klikovi = $row['klikovi']; $tim1=str_ireplace(array("\"","'","<",">"),"",$_POST['tim1']); $tim2=str_ireplace(array("\"","'","<",">"),"",$_POST['tim2']); $mtime=str_ireplace(array("\"",";","/","-"),":",$_POST['mtime']); $tip=str_ireplace(array("\"","'","<",">"),"",$_POST['tip']); $kvota=str_ireplace(array(","),".",$_POST['kvota']); $ulog=str_ireplace(array(","),".",$_POST['ulog']); $link=$_POST['link']; $ip=$_SERVER['REMOTE_ADDR']; $tim1=strtolower($tim1);$tim1=ucwords($tim1); $tim2=strtolower($tim2);$tim2=ucwords($tim2); $link=str_ireplace(" ","",$link); $prvoslovo=str_ireplace("http://www.flashscore.com/","#",$link); $linkDozvola=0; $today = mysql_query("select * from kurpal4_988.clanovi_njihovi_parovi where (clanovi_njihovi_parovi.datum >= current_date() - interval 1 day) and clanovi_njihovi_parovi.racun = 'some username' "); if($today==1); if($prvoslovo[0]=="#")$linkDozvola=1; if($linkDozvola==1 and $kvota>1 and $kvota<100){ $result = mysql_query("insert into clanovi_njihovi_parovi set racun='$racun',ip='$ip',datum=curdate(),vrijeme=curtime(),mtime='$mtime',tim1='$tim1',tim2='$tim2', tip='$tip', kvota='$kvota',ulog='$ulog',link='$link';"); } else if($today==0)echo "<script>alert('Please wait tomorrow.')</script>"; else if($linkDozvola==0)echo "<script>alert('Vas link je neispravan. Link utakmice kopirajte sa www.flashscore.com .')</script>"; else if($kvota<1.01 and $kvota>99.99)echo "<script>alert('Kvota vam nije u opsegu od 1.01 do 99.99 .')</script>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1513640 Share on other sites More sharing options...
Leverkusen Posted June 10, 2015 Author Share Posted June 10, 2015 (edited) Code looks like this now, i added this things but i can still post when i want. When posts is created i get this http://prntscr.com/7fj7xi 1st is post id and racun is user id $today = mysql_query("select * from kurpal4_988.clanovi_njihovi_parovi where (clanovi_njihovi_parovi.datum >= current_date() - interval 1 day) and clanovi_njihovi_parovi.racun = 'racun' "); if($today==1); else if($today==0)echo "<script>alert('Please wait tomorrow.')</script>"; <?php // upis para if($_POST['tim1']!="" and $_POST['tim2']!="" and $_POST['mtime']!="" and $_POST['tip']!="" and $_POST['kvota']!="" and $_POST['ulog']!="" and $_POST['link']!=""){ $racun=$_SESSION['liga_user_id']; $result = mysql_query("select * from clanovi_njihovi_racuni where id='$racun';"); $row = mysql_fetch_array($result); $profit = $row['profit']; $klikovi = $row['klikovi']; $tim1=str_ireplace(array("\"","'","<",">"),"",$_POST['tim1']); $tim2=str_ireplace(array("\"","'","<",">"),"",$_POST['tim2']); $mtime=str_ireplace(array("\"",";","/","-"),":",$_POST['mtime']); $tip=str_ireplace(array("\"","'","<",">"),"",$_POST['tip']); $kvota=str_ireplace(array(","),".",$_POST['kvota']); $ulog=str_ireplace(array(","),".",$_POST['ulog']); $link=$_POST['link']; $ip=$_SERVER['REMOTE_ADDR']; $tim1=strtolower($tim1);$tim1=ucwords($tim1); $tim2=strtolower($tim2);$tim2=ucwords($tim2); $link=str_ireplace(" ","",$link); $prvoslovo=str_ireplace("http://www.flashscore.com/","#",$link); $linkDozvola=0; $today = mysql_query("select * from kurpal4_988.clanovi_njihovi_parovi where (clanovi_njihovi_parovi.datum >= current_date() - interval 1 day) and clanovi_njihovi_parovi.racun = 'racun' "); if($today==1); if($prvoslovo[0]=="#")$linkDozvola=1; if($linkDozvola==1 and $kvota>1 and $kvota<100){ $result = mysql_query("insert into clanovi_njihovi_parovi set racun='$racun',ip='$ip',datum=curdate(),vrijeme=curtime(),mtime='$mtime',tim1='$tim1',tim2='$tim2', tip='$tip', kvota='$kvota',ulog='$ulog',link='$link';"); } else if($today==0)echo "<script>alert('Please wait tomorrow.')</script>"; else if($linkDozvola==0)echo "<script>alert('Vas link je neispravan. Link utakmice kopirajte sa www.flashscore.com .')</script>"; else if($kvota<1.01 and $kvota>99.99)echo "<script>alert('Kvota vam nije u opsegu od 1.01 do 99.99 .')</script>"; } ?> Edited June 10, 2015 by Leverkusen Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1513641 Share on other sites More sharing options...
Leverkusen Posted June 14, 2015 Author Share Posted June 14, 2015 I solved the problem adding this $today = mysql_query("SELECT COUNT(1) FROM `clanovi_njihovi_parovi` WHERE `racun` = {$racun} AND `datum` > DATE_SUB(NOW(), INTERVAL 1 DAY)");$row = mysql_fetch_array($today);$total_posts = $row[0]; if($total_posts <1) else if($total_posts>=1)echo "<script>alert('You already played today.')</script>"; Quote Link to comment https://forums.phpfreaks.com/topic/285730-limit-to-1-post-per-day/page/2/#findComment-1513857 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.