시간표가있는 데이터베이스가 있습니다. 즉
Class Start Day
Yoga 9:00:00 1,2,3
Golf 13:00:00 2,5,6
etc...
월요일 = 1, 화요일 = 2 등
현재는 오늘의 활동을 완벽하게 표시 할 수 있으며 어제 (전날, 전날 등), 내일 (다음날, 다음날 등)의 활동을 표시하는 방법을 추가하고 싶습니다. ...)
나는 Javascript와 ajax로 시도해 왔습니다 (나는 모든 종류의 웹 디자인과 언어를 배우기 시작했습니다). 이것은 매우 간단한 작업이어야하는 것 같지만 내가 무엇을 놓치고 있는지 알 수 없습니다. 다음은 오늘의 활동을 얻기위한 코드입니다.
<?php
//Create a connection
$con = mysqli_connect(
"*********", //host
"*********", //username
"*********", //password
"*********" //dbname
);
//check connection
if(mysqli_connect_errno())
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
//check if server is active
if(!mysqli_ping($con)){
printf("Error: %s\n", mysqli_error($con));
}
$result = mysqli_query($con, "
SELECT *
FROM schedules
ORDER BY Start ASC //Start time of event
");
/* print the Current Day in the Format:
Day, Month, Year
*/
echo "<h1 align='center'>".date('l, F j, Y') . "</h1><br>";
//todays date
$current_day = date('N');
echo "<ul data-role='listview' data-inset='true'>";
while($row = mysqli_fetch_array($result))
{
//if the event is on today then print the details
if(strpos($row['Day'], $current_day) !== false){
echo "<li>";
echo "<h1>".$row['Start']." - ".$row['End']."</h1>";
echo "<h2>".$row['Class']."</h2>";
echo "<h2>".$row['Instructor']."</h2>";
echo "</li>";
}
}
echo "</ul>";
//close connection
mysqli_close($con)
더 나은 솔루션은 단일 필드에 여러 값을 저장하는 것보다 데이터베이스에서 해당 필드를 분리하는 것입니다. 그러나 여기에 현재 디자인에서이 작업을 수행 할 수있는 방법이 있습니다. 먼저 어제 및 내일 변수를 정의하고 0 또는 8에 넘치지 않도록주의하십시오. 간결하게 유지하기 위해 삼항 연산자를 사용합니다.
$yesterday = (($current_day-1)!=0) ? ($current_day-1) : 7;
$tomorrow = (($current_day+1)!=8) ? ($current_day+1) : 1;
그런 다음 필요에 따라 while 블록을 업데이트하십시오.
while($row = mysqli_fetch_array($result))
{
//if the event is on today then print the details
if(strpos($row['Day'], $current_day) !== false){
echo "<li>";
echo "<h1>".$row['Start']." - ".$row['End']."</h1>";
echo "<h2>".$row['Class']."</h2>";
echo "<h2>".$row['Instructor']."</h2>";
echo "</li>";
}
if(strpos($row['Day'], $yesterday) !== false){
//do stuff
}
if(strpos($row['Day'], $tomorrow) !== false){
//do stuff
}
}
echo "</ul>";
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다