MNG Posted December 22, 2013 Posted December 22, 2013 Hey, I have been trying to figure out how to put a limit on the gang creations. I want it were only 8 gangs can be created in the game. Here is the file <?php include 'header.php'; if($_POST['create'] != ""){ // if they are wanting to start a new gang $error .= ($user_class->money < 25000) ? "<div>You don't have enough money to start a gang. You need at least ".'$25,000</div>' : $error; $error .= ($user_class->gang != 0) ? "<div>You have to leave your gang to start a new gang.</div>" : ""; $error .= (strlen($_POST['name']) < 3) ? "<div>Your Unit Name has to be at least 3 characters long.</div>" : ""; $error .= (strlen($_POST['name']) > 21) ? "<div>Your Unit Name can only be a max of 20 characters long.</div>" : ""; $error .= (strlen($_POST['tag']) < 1) ? "<div>Your Unit Name has to be at least 1 character long.</div>" : ""; $error .= (strlen($_POST['tag']) > 4) ? "<div>Your Unit Tag can only be a max of 4 characters long.</div>" : ""; $error = ($user_class->rmdays < 0) ? "You need to be a Respected Marine to make a Unit." : $error; //check if name is taken yet $check = mysql_query("SELECT * FROM `gangs` WHERE `name`='".$_POST['name']."'"); $exist = mysql_num_rows($check); $error .= ($exist > 0) ? "<div>The Unit Name you chose is already taken.</div>" : ""; //check if tag is taken yet $check = mysql_query("SELECT * FROM `gangs` WHERE `tag`='".$_POST['tag']."'"); $exist = mysql_num_rows($check); $error .= ($exist > 0) ? "<div>The tag you chose is already taken.</div>" : ""; if($error == ""){ // if there are no errors, make the gang $result= mysql_query("INSERT INTO `gangs` (name, tag, leader, level)"."VALUES ('".$_POST['name']."', '".$_POST['tag']."', '$user_class->id', '1')"); $newmoney = $user_class->money - 25000; //deduct the cost of the money $result = mysql_query("SELECT * FROM `gangs` WHERE `leader` = '".$user_class->id."'"); $worked = mysql_fetch_array($result); $gangid = $worked['id']; $result = mysql_query("UPDATE `grpgusers` SET `gangappliedto` = '0', `rankname` = 'Capo Crimini/Capo', `stat` = '1',`edit` = '2', `vault` = '2', `members` = '2', `ghouse` = '2', `ranks` = '2', `invite` = '2', `gang` = '$gangid', `rank` = '1', `money` = '".$newmoney."' WHERE `id`='".$_SESSION['id']."'"); $user_class = new User($_SESSION['id']); echo Message("You have successfully created a unit!"); } else { echo Message($error); } } if ($user_class->gang == 0) { ?> <tr><td class="contenthead">Create Unit</td></tr> <tr><td class="contentcontent"> <form method='post'> Well, it looks like you haven't join or created a unit yet.<br><br> To create a unit it costs $25,000. If you don't have enough, or would like to join someone elses unit, check out the <a href="gang_list.php">Unit List</a> for other gangs to join.<br><br> <table width='100%'> <tr> <td width='15%'>Unit Name:</td> <td width='35%'><input type='text' name='name' value='' maxlength='20' size='16'></td> <td width='15%'>Unit Tag</td> <td width='35%'><input type='text' name='tag' value='' maxlength='4' size='4'></td> </tr> <tr> <td colspan='4' align='center'><input type='submit' name='create' value='Create'></td> </tr> </table> </form> </td></tr> <?php } include 'footer.php'; ?> Thanks to all who help me on this. Quote
dnenb Posted December 22, 2013 Posted December 22, 2013 What exactly have you tried? I think something like this will work: //checks if there arent too many gangs already $max_amount_of_gangs = 5; $check = mysql_query("SELECT * FROM `gangs`"); $exist = mysql_num_rows($check); $error .= ($exist >= $max_amount_of_gangs) ? "<div>There are too many gangs already.</div>" : "" Quote
Veramys Posted December 22, 2013 Posted December 22, 2013 Just a question but why would you want to limit this? Isn't this a bit too restrictive? Stops your new users from being able to make a new gang. That would make me not wanna play. Quote
MNG Posted December 22, 2013 Author Posted December 22, 2013 (edited) Just a question but why would you want to limit this? Isn't this a bit too restrictive? Stops your new users from being able to make a new gang. That would make me not wanna play. Trust me once I am done with this project I can guaranteed you will change your words :) - - - Updated - - - What exactly have you tried? I think something like this will work: //checks if there arent too many gangs already $max_amount_of_gangs = 5; $check = mysql_query("SELECT * FROM `gangs`"); $exist = mysql_num_rows($check); $error .= ($exist >= $max_amount_of_gangs) ? "<div>There are too many gangs already.</div>" : "" Nothing lol I was getting my info from this article http://stackoverflow.com/questions/5749185/limit-a-variable-value-to-certain-predefined-values But thanks yours worked perfectly Edited December 22, 2013 by MNG Quote
Seker Posted December 22, 2013 Posted December 22, 2013 Trust me once I am done with this project I can guaranteed you will change your words :) Doubt it if you cannot even grasp if ($count > $max) 1 Quote
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.