Presný dátum a čas alebo ako ho upraviť

Místo pro dotazy a rady ohledně programovacích jazyků (C++, C#, PHP, ASP, Javascript, VBS..) a tvorby webových stránek

Moderátor: Mods_senior

Zeffo
nováček
Příspěvky: 1
Registrován: duben 12
Pohlaví: Muž
Stav:
Offline

Presný dátum a čas alebo ako ho upraviť

Příspěvekod Zeffo » 01 kvě 2012 18:56

Zdravím.
Mám taký formulár kde sa zadávajú výsledky do tabuľky. V tom formulári sa musí zadať dátum a čas odohratého zápasu.
Najprv to vyzerá takto :
Obrázek
Potom som to dal preč aby to nemuseli zadávať takže to vyzerá takto :
Obrázek
Oni keď stlačia "pridať" tak automaticky sa výsledky to tabulky započítajú. (ale to teraz neriešim).
Keď to teda stlačia :D tak sa tam zobrazí toto :
Obrázek
Ja chcem aby sa zobrazoval presný čas a dátum bez toho aby to museli hráči zadávať manuálne (viď obrázok 1)
PHP kod obrazka jedna (neni potrebný ale predsa)

Kód: Vybrat vše

<?php
/*
Form to add a score
*/

    $confid = intval($_GET['conf']);
    if ($is_admin || full_check('manage_score') || permissions_check('manage_score', $confid)) {
        $confname = getconf($confid);
        $seasonname = getseasonname($confid);
        print '<h2>Zapíš výsledok pre ' . $confname . ' konferenciu (' . $seasonname . ')</h2>' . "\n";
    ?>
<p>
Pridaj
 <select id="how_many" onchange="addScores();">
   <option value="1" selected>1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</<option>
   <option value="5">5</option>
   <option value="6">6</option>

 </select> zápas</p>
    <?php
       print "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "?action=addscoreyes&conf=$confid\">\n";
   ?>
<div id="add_score_form">
Dátum: <select name="month[]">
      <option value="1">Január</option>
     <option value="2">Február</option>
     <option value="3">Marec</option>
     <option value="4">Apríl</option>
     <option value="5">Máj</option>
     <option value="6">Jún</option>
     <option value="7">Júl</option>
     <option value="8">August</option>
     <option value="9">September</option>
     <option value="10">Október</option>
     <option value="11">November</option>
     <option value="12">December</option>
    </select>
      <input name="day[]" type="text" size="2" />
      <select name="year[]">
        <option value="<?php print $year_one; ?>"><?php print $year_one; ?></option>
        <option value="<?php print $year_two; ?>" selected><?php print $year_two; ?></option>
        <option value="<?php print $year_three; ?>"><?php print $year_three; ?></option>
      </select><br />
<div<?php if (!$show_fields) print " style=\"display:none;\""; ?>><br />1.hviezda zápasu: <input name="field[]" type="text" size="50" maxlength="50" /></div>
<br /><br /><select name="winner[]">
<?php
$query="SELECT sportsdb_teams.teamname, sportsdb_teams.teamid, sportsdb_divs.divname FROM sportsdb_teams
            LEFT JOIN sportsdb_divs ON sportsdb_teams.teamdiv = sportsdb_divs.divid
            WHERE (sportsdb_teams.active=1 AND sportsdb_divs.conference = $confid)
            OR sportsdb_teams.teamid = -1
            ORDER BY divorder ASC, teamname ASC";
$result=mysql_query($query);
while ($teams = mysql_fetch_array($result, MYSQL_ASSOC)) {
   print "<option value=\"{$teams['teamid']}\">{$teams['teamname']} ({$teams['divname']})</option>\n";
}
?>
</select>
<select name="winortie[]">
<option value="1">výhra nad</option>
<?php if ($forfeit)
print "<option value=\"2\">výhra(po prodlouzení)</option>\n";
?>
<option value="4">prohra nad</option>
<?php if ($forfeit)
print "<option value=\"5\">prohra (po prodlouzení)</option>\n";
?>
</select>
<select name="loser[]">
<?php
mysql_data_seek($result, 0);
while ($teams = mysql_fetch_array($result, MYSQL_ASSOC)) {
   print "<option value=\"{$teams['teamid']}\">{$teams['teamname']} ({$teams['divname']})</option>\n";
}
?>
</select><br />
Skóre: <input type="text" name="rf[]" size="3" maxlength="3" /> -
<input type="text" name="ra[]" size="3" maxlength="3" /><br />
<br /><br />
</div>
<script type="text/javascript">
// JavaScript to handle showing multiple "forms" on the same page
var add_score_form = document.getElementById('add_score_form');
var add_score_form_contents = add_score_form.innerHTML;
function addScores() {
    var how_many = parseInt(document.getElementById('how_many').value);
    var add_score_form_repeat = '';
    for (var i = 1; i <= how_many; i++) {
        add_score_form_repeat += '<h2>' + i + '</h2>' + add_score_form_contents + '<hr style="margin-top: 20px; margin-bottom: 20px;"/>';
    }
    add_score_form.innerHTML = add_score_form_repeat;
}
</script>
<input type="submit" value="Pridaj" />
</form>
<form method="get" action="<?php print $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="action" value="mainview" />
<input type="hidden" name="conf" value="<?php print $confid; ?>" />
</form>
<?php
    }

    else {
        die($text_no_perm);
    }
?>

PHP formulára obrazka 2 (potrebný)

Kód: Vybrat vše

<?php
/*
Form to add a score
*/

    $confid = intval($_GET['conf']);
    if ($is_admin || full_check('manage_score') || permissions_check('manage_score', $confid)) {
        $confname = getconf($confid);
        $seasonname = getseasonname($confid);
        print '<h2>Zapíš výsledok pre ' . $confname . ' konferenciu (' . $seasonname . ')</h2>' . "\n";
    ?>
<p>
Pridaj
 <select id="how_many" onchange="addScores();">
   <option value="1" selected>1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</<option>
   <option value="5">5</option>
   <option value="6">6</option>

 </select> zápas</p>
    <?php
       print "<form method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "?action=addscoreyes&conf=$confid\">\n";
   ?>
<div id="add_score_form">
/>1.hviezda zápasu: <input name="field[]" type="text" size="50" maxlength="50" /></div>
<br /><br /><select name="winner[]">
<?php
$query="SELECT sportsdb_teams.teamname, sportsdb_teams.teamid, sportsdb_divs.divname FROM sportsdb_teams
            LEFT JOIN sportsdb_divs ON sportsdb_teams.teamdiv = sportsdb_divs.divid
            WHERE (sportsdb_teams.active=1 AND sportsdb_divs.conference = $confid)
            OR sportsdb_teams.teamid = -1
            ORDER BY divorder ASC, teamname ASC";
$result=mysql_query($query);
while ($teams = mysql_fetch_array($result, MYSQL_ASSOC)) {
   print "<option value=\"{$teams['teamid']}\">{$teams['teamname']} ({$teams['divname']})</option>\n";
}
?>
</select>
<select name="winortie[]">
<option value="1">výhra nad</option>
<?php if ($forfeit)
print "<option value=\"2\">výhra(po prodlouzení)</option>\n";
?>
<option value="4">prohra nad</option>
<?php if ($forfeit)
print "<option value=\"5\">prohra (po prodlouzení)</option>\n";
?>
</select>
<select name="loser[]">
<?php
mysql_data_seek($result, 0);
while ($teams = mysql_fetch_array($result, MYSQL_ASSOC)) {
   print "<option value=\"{$teams['teamid']}\">{$teams['teamname']} ({$teams['divname']})</option>\n";
}
?>
</select><br />
Skóre: <input type="text" name="rf[]" size="3" maxlength="3" /> -
<input type="text" name="ra[]" size="3" maxlength="3" /><br />
<br /><br />
</div>
<script type="text/javascript">
// JavaScript to handle showing multiple "forms" on the same page
var add_score_form = document.getElementById('add_score_form');
var add_score_form_contents = add_score_form.innerHTML;
function addScores() {
    var how_many = parseInt(document.getElementById('how_many').value);
    var add_score_form_repeat = '';
    for (var i = 1; i <= how_many; i++) {
        add_score_form_repeat += '<h2>' + i + '</h2>' + add_score_form_contents + '<hr style="margin-top: 20px; margin-bottom: 20px;"/>';
    }
    add_score_form.innerHTML = add_score_form_repeat;
}
</script>
<input type="submit" value="Pridaj" />
</form>
<form method="get" action="<?php print $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="action" value="mainview" />
<input type="hidden" name="conf" value="<?php print $confid; ?>" />
</form>
<?php
    }

    else {
        die($text_no_perm);
    }
?>

a PHP kod obrazka č. 3 (chcem aby sa zobrazoval presný čas potrebujem teda zmeniť PHP kod tu chcem pomoct!! thx)

Kód: Vybrat vše

<?php
/*
Actually add a score
*/

    $confid = intval($_GET['conf']);
   
    if ($is_admin || full_check('manage_score') || permissions_check('manage_score', $confid) ) {
        $num_scores = count($_POST['day']);
        for ($i = 0; $i < $num_scores; ++$i) {
            $month = intval($_POST['month'][$i]);
            $day = intval($_POST['day'][$i]);
            $hour = intval($_POST['hour'][$i]);
            $minute = intval($_POST['minute'][$i]);
            $year = intval($_POST['year'][$i]);
            $ampm = $_POST['ampm'][$i];
            $windate = mktime(0, 0, 0, $month, $day, $year);
            if ($ampm == 'pm' && $hour != 12) {
                $hour = $hour + 12;
            }
            if ($ampm == 'am' && $hour == 12) {
                $hour = 0;
            }
           $wintime = mktime($hour, $minute, 0, $month, $day, $year);
           $wincomments = strip_tags($_POST['wincomments'][$i], '<font>');
            $wincomments = mysql_real_escape_string($wincomments);
           $field = strip_tags($_POST['field'][$i], '<font>');
            $field = mysql_real_escape_string($field);
            $winner=intval($_POST['winner'][$i]);
            $loser=intval($_POST['loser'][$i]);
            $rf=abs(intval($_POST['rf'][$i]));
            $ra=abs(intval($_POST['ra'][$i]));
            if ($winner == $loser && $winner != -1) {
                die ("You cannot have a team playing itself. <a href=\"" . $_SERVER['PHP_SELF'] . "?action=addscore&conf=$confid\">Please go back</a>.");
            }
            $winortie=intval($_POST['winortie'][$i]);

            // Insert the score

            $query="INSERT INTO sportsdb_wins (wincomments, field, windate, wintime, winner, loser, winortie, rf, ra, winconf) VALUES ('$wincomments', '$field', $windate, $wintime, $winner, $loser, $winortie, $rf, $ra, $confid)";
            $result=mysql_query($query) or die ("Error in query $query");

            // Update the number of ties, add runs scored and runs against

            if ($winortie == 0) {
                $query="UPDATE sportsdb_teams SET teamties = teamties +1, teamrf = teamrf +$rf, teamra = teamra +$ra WHERE teamid = $winner OR teamid = $loser";
                $result=mysql_query($query) or die ("Error in query $query");
            }

            // Update the number of wins and losses, add runs scored and runs against
            elseif ($winortie == 1) {
                $query="UPDATE sportsdb_teams SET teamwins = teamwins +1, teamrf = teamrf +$rf, teamra = teamra +$ra WHERE teamid = $winner";
                $result=mysql_query($query) or die ("Error in query $query");
                $query="UPDATE sportsdb_teams SET teamlosses = teamlosses +1, teamrf = teamrf +$ra, teamra = teamra +$rf WHERE teamid = $loser";
                $result=mysql_query($query) or die ("Error in query $query");
            }
            // Update the number of wins and losses, add runs scored and runs against when the away team won
            elseif ($winortie == 4) {
                $query="UPDATE sportsdb_teams SET teamwins = teamwins +1, teamrf = teamrf +$ra, teamra = teamra +$rf WHERE teamid = $loser";
                $result=mysql_query($query) or die ("Error in query $query");
                $query="UPDATE sportsdb_teams SET teamlosses = teamlosses +1, teamrf = teamrf +$rf, teamra = teamra +$ra WHERE teamid = $winner";
                $result=mysql_query($query) or die ("Error in query $query");
            }

            // Update the number of wins and forfeit losses, add runs scored and runs against when the home team wins
            elseif ($winortie == 2) {
                $query="UPDATE sportsdb_teams SET teamwins = teamwins +1, teamrf = teamrf +$rf, teamra = teamra +$ra WHERE teamid = $winner";
                $result=mysql_query($query) or die ("Error in query $query");
                $query="UPDATE sportsdb_teams SET teamforfeits = teamforfeits +1, teamrf = teamrf +$ra, teamra = teamra +$rf WHERE teamid = $loser";
                $result=mysql_query($query) or die ("Error in query $query");
            }

            // Update the number of wins and forfeit losses, add runs scored and runs against when the away team wins
            elseif ($winortie == 5) {
                $query="UPDATE sportsdb_teams SET teamwins = teamwins +1, teamrf = teamrf +$rf, teamra = teamra +$ra WHERE teamid = $loser";
                $result=mysql_query($query) or die ("Error in query $query");
                $query="UPDATE sportsdb_teams SET teamforfeits = teamforfeits +1, teamrf = teamrf +$ra, teamra = teamra +$rf WHERE teamid = $winner";
                $result=mysql_query($query) or die ("Error in query $query");
            }
            $scoretype = "game for";
            if ($winortie != 3) $scoretype = "score from";
            $stringtime = date('M j Y, g:ia', $wintime);
            print "Succesfully added the $scoretype $stringtime<br /><br />\n";
        }
        print "<a href=\"" . $_SERVER['PHP_SELF'] . "?action=mainview&conf=$confid\">Back</a><br />\n";
        print '<a href="' . $_SERVER['PHP_SELF'] . "?action=addscore&conf=$confid\">Add more</a>\n";
    }
   
    else {
        die($text_no_perm);
    }

?>

Díki za každú odpoveď ;) Dúfam, že ma chápete som lama :D

Reklama
Holi-cz
Level 2
Level 2
Příspěvky: 157
Registrován: říjen 10
Bydliště: Teplice
Pohlaví: Muž
Stav:
Offline
Kontakt:

Re: Presný dátum a čas alebo ako ho upraviť

Příspěvekod Holi-cz » 01 kvě 2012 19:27

Toto by Vám mohlo pomoci.


Zpět na “Programování a tvorba webu”

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 5 hostů