violaceous Posted September 25, 2011 Share Posted September 25, 2011 Hey all... I'm running into a problem here. If you take a look at the code for this, you'll see it's to enter "horses" into a "class." It's all fine and dandy except I'm trying to get the way the horses are selected to have a different option. Right now they exist as a drop down/select option where you have to choose one at a time and enter submit. My goal is to have checkboxes that users can toggle and submit them all at once (with the rest of the eligibility checks etc still applicable). I've looked it up and the problem is, each user has a different amount of horses, so I can't account for all of them manually. Could someone help me out? On DaniWeb a user was trying to help me with an implode option, but I have zero idea how to work with that. I will literally need my hand to be held through this one. Thank you in advance - I have been trying to do this myself for a good chunk of the day, but my PHP skills are quite limited. <?php session_start(); // Maintain session state header("Cache-control: private"); // Fixes IE6's back button problem. $page_title = "Class Information"; include('header.php'); $class_id = $_GET['id']; $enter = $_POST['enter_horse']; $enter_check = $_POST['check']; $horse_id = $_POST['horse_id']; //general show information $result = @mysql_query("SELECT s.show_id, s.player_id, s.type, s.name, DATEDIFF(s.run_date, NOW()) AS datedif, c.class_id, s.entry_fee FROM classes c, shows s WHERE c.class_id='$class_id' AND c.show_id=s.show_id LIMIT 1")or die("Cannot find class! " . mysql_error()); $row = @mysql_fetch_array($result); $show_id = $row['show_id']; $show_name = $row['name']; $runs_in = $row['datedif']; $species = $row['species']; $type = $row['type']; $owner_id = $row['player_id']; if(!$row['class_id']){myError("Invalid class!");include('footer.php');} $entry_fee = $row['entry_fee']; $num_entries = @mysql_num_rows(@mysql_query("SELECT horse_id FROM horses_entered WHERE class_id='$class_id'")); $runs_in = "$runs_in day[s]"; if($enter){ //ensure horse is eligible to enter $good = @mysql_num_rows(@mysql_query("SELECT horse_id FROM horses WHERE horse_id='$horse_id' AND player_id='$player_id' AND age>=2 AND age<=20")); $exists = @mysql_num_rows(@mysql_query("SELECT horse_id FROM horses_entered WHERE horse_id='$horse_id' AND class_id='$class_id' LIMIT 1")); if($my_money < $entry_fee){myError("You cannot afford the entry fee.", 1);} if(!$good){myError("Are you sure you own the horse and it is between 3 and 20 years of age?"); }elseif($exists){myError("That horse is already entered in this class!"); }else{ @mysql_query("INSERT INTO horses_entered(horse_id, class_id) VALUES('$horse_id', '$class_id')")or die("Cannot create entry!"); if($type == 1 AND $entry_fee){@mysql_query("UPDATE players SET money=money+'$entry_fee' WHERE player_id='$owner_id' LIMIT 1")or die("Cannot update player money!"); $points=1; }elseif($type == 2 AND $entry_fee){@mysql_query("UPDATE clubs SET money=money+'$entry_fee' WHERE president='$owner_id' LIMIT 1")or die("Cannot update player money2!"); $points=2;} @mysql_query("UPDATE players SET money=money-'$entry_fee', points=points+'$points' WHERE player_id='$player_id' LIMIT 1")or die("Cannot update player money3! " . @mysql_error()); @mysql_query("UPDATE horses SET points=points+'$points' WHERE horse_id='$horse_id' LIMIT 1")or die("Cannot update horse points!"); myError("Class entered!"); } } //display the show information echo "<table> <tr><td><b>Class:</td><td>#$class_id</td></tr> <tr><td><b>Show:</td><td><a href='shows.php?id=$show_id'>$show_name (#$show_id)</a></td></tr> <tr><td><b>Runs:</td><td>$runs_in</td></tr> <tr><td><b>Entry Fee:</td><td>$$entry_fee</td></tr> <tr><td><b>Total Entrants:</td><td>$num_entries</td></tr> <tr><td valign=top><b>Your Horses:</td><td> <form action='classes.php?id=$class_id' method=POST> <select name='horse_id'> "; $result = @mysql_query("SELECT horse_name, breed, horse_id FROM horses WHERE player_id='$player_id' AND age>2 AND age<=20 ORDER BY horse_name ASC")or die("Cannot find horses! " . mysql_error()); while($row = @mysql_fetch_array($result)): $horse_id = $row['horse_id']; $horse_name = stripslashes($row['horse_name']); $breed = $row['breed']; echo "<option value='$horse_id'>$horse_name (#$horse_id), $breed</option>\n"; $prev_species = $species; endwhile; if(!$horse_id){echo "<option value=0>No eligible horses!";} echo " </select> <input type=submit name='enter_horse' value='Enter Horse!'></td></tr></form> <tr><td valign=top><b>Entrants:</td><td> "; $query = "SELECT h.horse_name, h.horse_id, h.breed FROM horses_entered he LEFT JOIN horses h ON he.horse_id=h.horse_id WHERE he.class_id='$class_id' ORDER BY h.horse_name ASC"; $result = @mysql_query($query)or die(mysql_error()); while($row = @mysql_fetch_array($result)): $name = $row['horse_name']; $aid = $row['horse_id']; $breed = $row['breed']; $page = "horses.php"; echo "<a href='$page?id=$aid'>$name (#$aid)</a>, $breed<br>\n"; endwhile; if(!$aid){echo "<i>No entrants.";} echo "</td></tr> </table>"; include('footer.php'); ?> Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted September 26, 2011 Share Posted September 26, 2011 I'm not sure what's going on here, but you shuld absoloutly NEVER suppress (use of @ symbol) any function call - ever. All your @'s that are in that code need to go - especialy the ones on the mysql_() functions - or you'll just be scratching your head when something goes wrong and you have nothing on screen to tell you what that is. Right, that said, could you give us all a clear breakdown of what you have in place just now and what you are looking for? Also an overview of the general design would probably help as well, although is not as important. Quote Link to comment Share on other sites More sharing options...
violaceous Posted September 26, 2011 Author Share Posted September 26, 2011 I didn't program this myself, so I'd have no idea how to revamp it to make it cleaner The website this is a part of has different user accounts where members buy 'horses' and 'train' them by entering them into 'classes' which are a part of 'shows.' The horse gains points and everyone wants the horse to have the highest amount. Etc, etc. So, basically, this is a "classes" page. A user clicks the class, sees the list of entrants, and the list of their eligible horses that they can enter. However as it is right now, there is a drop down list of their horses which they have to select and submit one by one. I was just wondering if it's possible to have their eligible horses display as multiple checkboxes instead so that they can select multiple horses at once and hit submit. Unless you have a better idea of how to do that - I wouldn't even mind a 'submit all eligible horses' button, although the users would probably rather have the checkboxes so they can pick and choose... Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted September 26, 2011 Share Posted September 26, 2011 and how many horses, adverage and maximum, do the players have? Quote Link to comment Share on other sites More sharing options...
violaceous Posted September 26, 2011 Author Share Posted September 26, 2011 I would say average is 2-5, but some people have just the 1. They can have as many horses as they wish, but not all of them will be showing up because they won't fit the eligibility. I would also be surprised to see more than 200 horses in an account. I'd be surprised to see more than 10 horses that were being entered into shows. Quote Link to comment Share on other sites More sharing options...
violaceous Posted September 28, 2011 Author Share Posted September 28, 2011 Okay, let's scratch the checkbox idea. Is it possible to have the submit button work to submit all results, instead of one at a time? <form action='classes.php?id=$class_id' method=POST> <select name='horse_id'> "; $result = @mysql_query("SELECT horse_name, breed, horse_id FROM horses WHERE player_id='$player_id' AND age>2 AND age<=20 ORDER BY horse_name ASC")or die("Cannot find horses! " . mysql_error()); while($row = @mysql_fetch_array($result)): $horse_id = $row['horse_id']; $horse_name = stripslashes($row['horse_name']); $breed = $row['breed']; echo "<option value='$horse_id'>$horse_name (#$horse_id), $breed</option>\n"; $prev_species = $species; endwhile; if(!$horse_id){echo "<option value=0>No eligible horses!";} echo " </select> <input type=submit name='enter_horse' value='Enter Horse!'></td></tr></form> <tr><td valign=top><b>Entrants:</td><td> "; Instead of the option value and showing the drop down select menu and doing it one at a time... is it possible to show the list of horses, and on submit have all of those particular results submitted through the query? Quote Link to comment 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.