Entering Date in database

Hello PHP Help,

line 46 echo works fine.

// echo "<div>" . $date-> format('D Y-m-d') . "</div>";
Capture

I am trying to insert these values into the database.
error that I am geting is this:

also, i will incllude the structure of the fields.

I searched for a solution, and I tried many things.
Mostly trying to enter that $date as integer, date and string. no luck so far.

It is time to ask for help.

here is my php.

<!DOCTYPE html>
<html>
<body>
<?php include "includes/db.php"; ?>
<?php 
/**
 *  @begin    string A date/time string that can be accepted by the DateTime constructor.
 *  @end      string A date/time string that can be accepted by the DateTime constructor.
 *  @interval string An interval specification that can be accepted by the DateInterval constructor.
 *                   Defaults to P1D
 *
 *  @return   array Array of DateTime objects for the specified date range.
 */
function dateRange($begin, $end, $interval = null)
{
    $begin = new DateTime($begin);
    $end = new DateTime($end);
    // Because DatePeriod does not include the last date specified.
    $end = $end->modify('+1 day');
    $interval = new DateInterval($interval ? $interval : 'P1D');

    return iterator_to_array(new DatePeriod($begin, $interval, $end));
}

$dates = dateRange('2019-09-18', '2020-05-13');

//$weekends = array_filter($dates, function ($date) {
//    $day = $date->format("N");
//    return $day === '6' || $day === '7';
//});

//foreach ($weekends as $date) {
 //   echo $date->format("D Y-m-d") . "\n";
//}

$wednesdays = array_filter($dates, function ($date) {
    return $date->format("N") === '3';
});


foreach ($wednesdays as $date) {
$query = "INSERT INTO wednesdays (wednesday)";
$query.= "VALUES ('$date')";
  // echo "<div>" . $date-> format('D Y-m-d') . "</div>";

$date_query = mysqli_query($connection, $query);
if(!$date_query) {
	die("Query Failed!" . mysql_error($connection) . ' ' . mysqli_errno($connection));

	}
}

while ($row = mysqli_fetch_array($select_date_query)){

echo $db_wed = $row['wednesday'];

}
 ?>

</body>
</html>

TY

All I can really think of is, why? Why have a table with a column of “Wednesday”? What are you actually trying to do and why is a database involved at all?

Ultimately.This is what I am thinking.

I am creating a schedule of players.
a player logs in and
scrolls thru wednesdays the id will be Week[$id] according to the wednesdays.

and give your opponent’s contact information.

somethihng like.

Week 1 -Wednesday July 4th.2020.

opponent- J.Wilson
Phone:555-555-5555
Email: jwilson @ heree.com

with score and a place to submit scores, give your current win - loss record.

currently in a excel spreadsheet. I want this to be accessed form a webpage an app possibly

xcelCapture

So I am not seeing a reason for a table of nothing but wednesdays, that can all be handled at the code level. Submitting scores is an easy CRUD operation. Win/ Loss records are just a database query that could be turned into a view. For what goes into the database, you would have a participant id, the date of the match, and depending on how you wanted, either scores themselves or just a winner/ loser status.

Participant
id
name

Match
id
date

Match_Participants
id
match_id
participant_id
// there would be two records here but this allows scale if three or more are to play

Match_Score
id
match_id
participant_id
score

Something along those lines.

Now, there is also the possiblity with this to utilize NoSQL and just store everything in a single entry and do something like this:

{ 
    "match_date" : "2019-09-25",
    "participants" : [
        {"name" : "Mark", "score" : 25 },
        {"name" : "John", "score" : 35 }
    ],
    "winner" : "John" 
}

Depending on the version of MySQL you are using, there is support for JSON.

why an id column for the Match_Participants table while a two column primary key on match_id and participant_id would do?

why two times almost the same table? You could make a score column in the join table Match_Participants.

1 Like

Yes on all of those points

Sponsor our Newsletter | Privacy Policy | Terms of Service