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');
?>