Smudly Posted July 14, 2010 Share Posted July 14, 2010 Hi, I'm currently working on a support page. Right now, it successfully allows a user to type in a question, where the information is inserted into my database. With one flaw though. There is a check that ensures the user doesn't have more than 3 questions at a time. I need to have this check for questions that also have a status "answered" set to 'no'. For example: For every question that the user asks, the answered status is set to 'no' by default. If the user has more than 3 unanswered questions at any time, they won't be able to ask another question. If they have 5 questions they have asked though perhaps, but 4 are set to 'yes', and 1 is set to 'no, they will be able to ask a question. What should I change to get this to work properly? Thanks <?php session_start(); $username = $_SESSION['username']; if(isset($_SESSION['username'])){ $submit = $_POST['submit']; if($submit){ include_once('inc/connect.php'); $supportsql = mysql_query("SELECT * FROM `users` WHERE `username`='$username'"); $row = mysql_fetch_assoc($supportsql); $userid = $row['id']; $message = $_POST['problem']; $date = date("Y-m-d"); $checksql = mysql_query("SELECT id FROM `support` WHERE `id`='$userid'"); $idcount = mysql_num_rows($checksql); $checkmessage = mysql_query("SELECT message FROM `support` WHERE `message`='$message'"); $messagecount = mysql_num_rows($checkmessage); // Fix this to take in account if the question has already been answered. if ($idcount<=2){ if ($messagecount==0){ $supportquery = "INSERT INTO support VALUES ('','$userid','$username','$message','no','$date')"; $supportresult = mysql_query($supportquery) or die("Error Inputting Message"); } else{ $error = "You have already submitted this question. It will be replied to within 24 hours."; } } else{ $error = "Sorry, you currently have 3 Support Tickets awaiting to be answered.<br />Please wait until these are answered before asking another question."; } } } else{ header("Location: index.php"); } ?> <html> <head> <title>Support</title> </head> <body OnLoad="document.support.problem.focus();"> <center> <h1>Get Support!</h1> <form name="support" action="support.php" method="POST"> <textarea rows="8" cols="50" name="problem"><?php echo $message; ?></textarea><br /> <input type="submit" name="submit" value="Submit"> </form> <br /> <?php echo $error; ?> </center> </body> </html> Link to comment https://forums.phpfreaks.com/topic/207676-checking-number-of-rows-and-checking-status-of-row/ Share on other sites More sharing options...
ocpaul20 Posted July 14, 2010 Share Posted July 14, 2010 How are you going to stop the same questions, worded differently? You cannot, so it is just a matter of counting how many questions this user has in the table with the answered flag set to 'no'. Besides, if the questions are answered promptly, then people will not ask more than one question about the same support issue. Link to comment https://forums.phpfreaks.com/topic/207676-checking-number-of-rows-and-checking-status-of-row/#findComment-1085666 Share on other sites More sharing options...
Pikachu2000 Posted July 14, 2010 Share Posted July 14, 2010 SELECT COUNT(`answered`) AS a FROM `support` WHERE `user_id` = $user_id AND `yesno` = 'no' I don't know what your field names are, but this should be a nudge in the right direction. Link to comment https://forums.phpfreaks.com/topic/207676-checking-number-of-rows-and-checking-status-of-row/#findComment-1085683 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.