473,386 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

posting an array or using checkboxes

Hi everyone,
I need some help. I'm trying to tweak a code and keep hitting my head against a wall. It's for a game that I am running where a user has "horses" that they enter into "classes" which are a part of "shows." They can have multiple horses and no limits, however the horse has to meet certain requirements in order to enter the classes. At the class page, a user sees their eligible horses in a drop down select list, they hit submit, and the horse is entered. They have to do this multiple times for each of their horses. However, I am trying to make it so that they can either a) see a submit all eligible horses button, which would insert all of the eligible horses with one click or b) see their list of eligible horses as checkboxes where they can select which ones they want and submit and have the horses inserted. I really don't care which it is, if it's easier to do the submit all that's fine. I was trying to get the checkbox portion to work, but I haven't had any luck. Any help would be much appreciated. Here is the code:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start(); // Maintain session state
  3. header("Cache-control: private");    // Fixes IE6's back button problem.
  4. $page_title = "Class Information";
  5.  
  6. include('header.php');
  7. $class_id = $_GET['id'];
  8. $enter = $_POST['enter_horse'];
  9. $check = $_POST['check'];
  10. $horse_id = $_POST['horse_id'];
  11.  
  12.  
  13. //general show information
  14. $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());
  15. $row = @mysql_fetch_array($result);
  16.     $show_id = $row['show_id'];
  17.     $show_name = $row['name'];
  18.     $runs_in = $row['datedif'];
  19.     $species = $row['species'];
  20.     $type = $row['type'];
  21.     $owner_id = $row['player_id'];
  22.     if(!$row['class_id']){myError("Invalid class!");include('footer.php');}
  23.     $entry_fee = $row['entry_fee'];
  24.     $num_entries = @mysql_num_rows(@mysql_query("SELECT horse_id FROM horses_entered WHERE class_id='$class_id'"));
  25.     $runs_in = "$runs_in day[s]";
  26.  
  27. if($enter){
  28.     //ensure horse is eligible to enter
  29.     $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"));
  30.     $exists = @mysql_num_rows(@mysql_query("SELECT horse_id FROM horses_entered WHERE horse_id='$horse_id' AND class_id='$class_id' LIMIT 1"));
  31.     if($my_money < $entry_fee){myError("You cannot afford the entry fee.", 1);}
  32.     if(!$good){myError("Are you sure you own the horse and it is between 3 and 20 years of age?");
  33.     }elseif($exists){myError("That horse is already entered in this class!");
  34.     }else{
  35.         @mysql_query("INSERT INTO horses_entered(horse_id, class_id) VALUES('$horse_id', '$class_id')")or die("Cannot create entry!");
  36.         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;
  37.         }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;}
  38.         @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());
  39.         @mysql_query("UPDATE horses SET points=points+1 WHERE horse_id='$horse_id' LIMIT 1")or die("Cannot update horse points!");
  40.         myError("Class entered!");
  41.     }
  42. }
  43.  
  44. //display the show information
  45. echo "<table>
  46. <tr><td><b>Class:</td><td>#$class_id</td></tr>
  47. <tr><td><b>Show:</td><td><a href='shows.php?id=$show_id'>$show_name (#$show_id)</a></td></tr>
  48. <tr><td><b>Runs:</td><td>$runs_in</td></tr>
  49. <tr><td><b>Entry Fee:</td><td>$$entry_fee</td></tr>
  50. <tr><td><b>Total Entrants:</td><td>$num_entries</td></tr>
  51. <tr><td valign=top><b>Your Horses:</td><td>
  52. <form action='classes.php?id=$class_id' method=POST>
  53. <select name='horse_id'>
  54. ";
  55. $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());
  56. while($row = @mysql_fetch_array($result)):
  57.     $horse_id = $row['horse_id'];
  58.     $horse_name = stripslashes($row['horse_name']);
  59.     $breed = $row['breed'];
  60.     echo "<option value='$horse_id'>$horse_name (#$horse_id), $breed</option>\n";
  61.     $prev_species = $species;
  62. endwhile;
  63. if(!$horse_id){echo "<option value=0>No eligible horses!";}
  64.  
  65.  
  66. echo "
  67. </select> &nbsp;&nbsp;
  68. <input type=submit name='enter_horse' value='Enter Horse!'></td></tr></form>
  69. <tr><td valign=top><b>Entrants:</td><td>
  70. ";
  71. }
  72.  
  73. $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";
  74. $result = @mysql_query($query)or die(mysql_error());
  75. while($row = @mysql_fetch_array($result)):
  76.     $name = $row['horse_name'];
  77.     $aid = $row['horse_id'];
  78.     $breed = $row['breed'];
  79.     $page = "horses.php";
  80.     echo "<a href='$page?id=$aid'>$name (#$aid)</a>, $breed<br>\n";
  81. endwhile;
  82. if(!$aid){echo "<i>No entrants.";}
  83. echo "</td></tr>
  84. </table>";
  85.  
  86. include('footer.php');
  87. ?>
It's the if($enter) & enter_horse form that are the original part that I would like to change and add on as a separate thing (it will only display to certain users).
Sep 28 '11 #1
3 1537
johny10151981
1,059 1GB
in general i use a simple trick on situation like send same type of data with unknown type.

as example, if you are making a sale, you don't know how many sale line you will make, the simplest trick is something below:
Expand|Select|Wrap|Line Numbers
  1. <form>
  2. <intput id='x_1'>
  3. <intput id='x_2'>
  4. <intput id='x_3'>
  5. <intput id='x_4'>
  6. <INPUT type='hidden' id='length' value=4>
  7. </form>
  8.  
you can implement this in various ways....
Sep 28 '11 #2
Thanks for your response. Would you mind expanding upon your solution? I'm sorry, I don't necessarily understand how to implement what you're talking about into my code.

I was thinking, could a foreach system be used for this? Or am I way off?
Sep 28 '11 #3
johny10151981
1,059 1GB
after submitting the data (say as POST) you will get
Expand|Select|Wrap|Line Numbers
  1. //$_POST['x_1']
  2. //$_POST['x_2']
  3. //$_POST['x_3']
  4. //$_POST['x_4']
  5. //$_POST['length'];
  6.  
  7. $length=$_POST['length']; //make sure this index exists
  8. //now access like below:
  9. for($i=1;$i<=$length;$i++)
  10. {
  11.   echo $_POST['x_'.$i]."<br>";
  12. }
  13.  
  14.  
try this out
Sep 29 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Sontu | last post by:
Consider the following code: int main(void) { char buffer; func(buffer); } void func(char *bufpas) {
3
by: Mark | last post by:
I am looking for an example of using checkboxes in a repeater control where the checkbox state is persisted from page to page. Thank you, Mark
31
by: arun | last post by:
suppose i have a pointer to an array of integers.can i initialize each member of the array using pointers?plz explain
5
by: Krish | last post by:
Hello People I hope I am On Topic. Anyways, here is my problem. Any insights would be really appreciated. I have wrapped a C IO module using SWIG -> Python Module. Suppose the name of the...
8
by: Skay | last post by:
Someone challenged me to create a dynamic multidimensional array using auto_ptr http://www.gotw.ca/gotw/042.htm Provides a good way to create a single dimensional array using an adapter. ...
4
by: mVosa | last post by:
I have this piece of code in a funtion which is trying to retrieve the memory address of values that are stored in a 2D array, using pointers...Could I get help or tips on how to do this please...
0
by: shameem | last post by:
hi 2 all, my question is how to delete the records by using checkboxes in datagrid. pls give reply to my question.
1
by: geervani | last post by:
hello, Can anybody just tell me how to scan or input a 2d array using pointer i e indirect reference. I am allocating memory the array dynamically. the statement i am using is int *a;...
3
by: SM | last post by:
Hello, I have an array that holds images path of cd covers. The array looks like this: $cd = array( 589=>'sylver.jpg', 782=>'bigone.jpg', 158=>'dime.jpg' );
8
by: anandmms | last post by:
Hello friend, my problem is to save more than one fingerprint images in one byte array and then store in database(oracle). i dont know how to solve it. But previously i had did image saving...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.