Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
web based table editing

Posted by bschultz (bschultz), 22 April 2003
Hi 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.

For example:

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.

Thanks.

Brian

Posted by admin (Graham Ellis), 22 April 2003
This 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 2003
I 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
Code:
function drop_down_box_options($sql,$default="")
{
     $result=array_from_mysql_query($sql);
         // the above line refers to function written by me to get a full result array from an sql command.
     for($i=0;$i<sizeof($result);$i++)
     {
           $output.= '<option value="';
           $output.= $result[$i][0];
           if ($default==$result[$i][0])
           {
                 $output.= '" selected>';
           }
           else
           {
                 $output.= '">';
           }
           $output.= $result[$i][1];
           $output.= '</option>';
           $output.= "\n";
     }
     return $output;
}



Use the code in the following manner

<select name="sports">
<?php
$sql="SELECT * FROM sports";
echo drop_down_box_options($sql);
?>
</select>

You can also save a bit of coding time and reuse the input form to edit the details.

eg.

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.

if(!empty($_GET['ref']))
{
  // get event details from the database using a where clause of "event_ref=34"
  //setup defaults using data
  $defaults['event_ref']=values;
  $defaults['sport_ref']=values;
}
else
{
  // set up blank defaults
  $defaults['event_ref']=0;
  $defaults['sport_ref']=1;
}

<form name="event_add" method="post" .....>
<input type="hidden" name="event_ref" value="<?php echo $default["event_ref"]; ?>"/>
<select name="sports">
<?php
$sql="SELECT * FROM sports";
echo drop_down_box_options($sql,$default["sport_ref"]);
?>
</select>
.
</form>

------------
when proccessing

if($_POST["event_ref"]==0)
{
// INSERT values into database
}
else
{
 // UPDATE values in database WHERE event_ref=$_POST["event_ref"]
}



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho