web based table editing
Posted by bschultz (bschultz), 22 April 2003Hi all,
I'm back! I've got my site (high school sports statistics / results) up with PHP and MySQL. I've got a question, though.
Since the spring weather isn't very good, there are a LOT of scheduling changes. The way I wrote the code, there is a simple "call" for the "Score" cell in the table for the schedule for that particular sport, so that the results display after the coach submits the info. There is also a "call" for the same cell on the main page of the site, where all of the schedules / results for all seven sports show up.
I also have a separate submit page for each game / event for each sport. That's how I call the proper script for each game.
softball submit game1.html writes to MySQL database "softball" for table "game1"
I then call up that table in game1.php to display the results.
If we have a game rescheduled because of the weather, game 1 might come after game 5...which is confusing to keep straight which game needs to go where. I also have to worry about the "submit" page to make sure that it has the right date / game # combination.
Is there a way to make this all web-based...where I can edit all of this easily?
If this didn't make sense, let me know, and I'll try to clarify it.
Posted by admin (Graham Ellis), 22 April 2003This sounds rather like one of those cases where you need to generalise you code and hold things in variables rather than having lots of separate pages. It can make things devilishly hard to get your head around while you're coding and maintaining, but it makes for a neat, robust, easily modified application when you do succeed.
OK - that was an easy paragraph of "woffle" for me to write. It gets a bit more tricky for me to give you a detailed "how to". How about starting off with a table or file of games, dates, game no.s, etc - then generating each form in PHP from a single page. If a game moves, all you need to do is to change the date and everything else should be fine if you've got it right. Like I say, not
easy to code the first time you do something like this, but very flexible and think of all the boring page duplication you're going to be saving yourself in the medium to long term.
Your question was actually about making these changes web based ... well, once you have the dates and games in a table or file, it's just another little PHP script
Posted by waygood (waygood), 1 July 2003I think you need to sit down and write down what each entry has in common with all the others. tHis will help you reduce your code to a minimum.
This is an event scheduling system, so work around that.
You would then only have 3 forms, add an event, search for an event and amend an event.
Each event would have a date, sport and other information you would supply yourself.
You would then select the sport from a drop down list, select the date/time and enter the other information. When an event is re-scheduled you would then search for it (eg search by date/name) then edit it and change the information required (usually date).
You would have a table of the different sports and a table of the events. You could then add a sport without having to add another set of forms
This may help with your drop down box
Use the code in the following manner
$sql="SELECT * FROM sports";
You can also save a bit of coding time and reuse the input form to edit the details.
add_event.php will add an event, BUT using add_event.php?ref=34 will edit event 34.
This is achieved by testing for $_GET at the start and setting up the default values.
// get event details from the database using a where clause of "event_ref=34"
//setup defaults using data
// set up blank defaults
<form name="event_add" method="post" .....>
<input type="hidden" name="event_ref" value="<?php echo $default["event_ref"]; ?>"/>
$sql="SELECT * FROM sports";
// INSERT values into database
// UPDATE values in database WHERE event_ref=$_POST["event_ref"]
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: email@example.com • WEB: http://www.wellho.net • SKYPE: wellho