PHP - Php Homework
I got stuck with one question of my php homework. Hope u guys can help and advise the step by step codings. About the subject, There is no PHP that can be selected in Course Hero
please see below question
Question 1:
Following is the implementation of date time function in php:
<?php $dateString = date("Y/m/d h:i:s"); //current date with format echo "Today is $dateString<br>"; //mktime(hour,minute,second,month,day,year) $mydate = mktime(13, 34, 46, 12, 24, 2017); $dateString = date("Y/m/d h:i:sa", $mydate); echo "My Date is $dateString<br>"; $errordate = mktime(25,25,-1,15,32,1900); $dateString = date("Y/m/d h:i:sa", $errordate); echo "Error Date is $dateString<br>"; ?>
To get simple date, you have one of the parameters format in date(). Few characters need to be specified within the parameter.
'd' for the day of month (1-31) 'm' for month number (1-12) 'y' stands for year(it should be 4 digit) 'h' shows 12 hour format (01 - 12) 'I' shows minutes with zeroes(00-59) 's' denotes seconds (00-59) 'a' denotes am or pm.
The mktime() function is an inbuilt function in PHP which is used to return the Unix timestamp for a date.
The timestamp returns a long integer containing the number of seconds between the Unix Epoch (January 1, 1970, 00:00:00 GMT) and the time specified.
Without the parameter, mktime() will return the current timestamp of your server.
However, you will find that there will have an error on display the date or time if users pass some value which do not follow the rule of date and time, e.g. month is 13.
You are required to write new function with name validDate($month, $day, $year) which will return an error message "Invalid parameter(s) for the date!" if passing an invalid parameters to this function. If no error found, return the date in string with "Y/m/d" format.
Example codes:
<?php $dateString = validDate(13,32,1969); echo "My Date is $dateString<br>"; $dateString = validDate(12,31,2018); echo "My Date is $dateString<br>"; ... ?> Similar TutorialsI need help debugging some homework.I have narrowed the problem down to the switch. when it gets to the switch it is spitting out the default everytime, also in the default the $score in both echo statment is not showing. Its probably something small killing me I just can't see it and dont have enough experience with php yet.
<body> <?php $faceNamesSingular = array("one", "two", "three", "four", "five", "six"); $faceNamesPlural = array("ones", "twos", "threes", "fours", "fives", "sixes"); function checkForDoubles($die1, $die2) { global $faceNamesSingular; global $faceNamesPlural; $returnValue = false; if ($die1 == $die2) { //Doubles echo "The roll was double ", $faceNamesPlural[$die1-1], ".<br />"; $returnValue = true; } else { // Not Doubles echo "The roll was a ", $faceNamesSingular[$die1-1], " and a ", $faceNamesSingular[$die2-1], ".<br />"; $returnValue = false; } return $returnValue; } function displayScoreText($scores, $doubles) { switch ($score) { case 2: echo "You rolled snake eyes!<br />"; break; case 3: echo "You rolled a loose deuce!<br />"; break; case 5: echo "You rolled a fever five!<br />"; break; case 7: echo "You rolled a natural!<br />"; break; case 9: echo "You rolled a nina!<br />"; break; case 11: echo "You rolled a yo!<br />"; break; case 12: echo "You rolled boxcars!<br />"; break; default: if ($score % 2 == 0) {//any even number if ($doubles) { echo "You rolled a hard $score!<br />"; } else { //Not Doubles echo "You rolled an easy $score!<br />"; } } break; } } $dice = array(); $dice[0] = rand(1,6); $dice[1] = rand(1,6); $score = $dice[0] + $dice[1]; echo "<p>"; echo "The total score for the roll was $score.<br />"; $doubles = checkForDoubles($dice[0], $dice[1]); displayScoreText($score, $doubles); echo "</p>"; ?> </body> </html>Attached Files DiceRoll.php 1.94KB 0 downloads Hi, Trying to build a simple homework manager for the school I am Head of ICT in, using PHP and MySQL. Currently at the design stage - so no code to share yet. But I will share with you how I intend to get it working, and the issue I have... I anticipate having 5 tables Table 1 Student_ID | Student_name Table 2 Class_ID | Teacher_name Table 3 Student_ID | Class_ID Table 4 Class_ID | Class_name Table 5 Class_ID | Activity | Date_set | Date_due | Visible So, at its simplest it should be possible to select from the database all classes that match your student_id and show the homework set for those. Also, I have a visible tag set so that teachers can pseudo delete homeworks using a small control panel. But what I would like to do, is allow the students to set whether or not they have done the homework (kind of like a task in remember the milk) - but obvioulsy they cant have access to the database. Anyone got any idea how this could be achieved? |