2016-02-05 115 views
0

我目前正在一個網站上顯示一個運動隊的「固定裝置」,但所有數據都是從另一個網站獲取的。比較從API獲取的日期到今天的日期

我有一個得到所有的數據,包括下一個對手,日期,時間等

我張貼每個燈具到列表中的踢,然後每個元素到不同的div的API。

E.g.每個燈具 - <li><div>Date of Fixture</div> <div>Kick off time</div> <div>Home Team</div> <div>Away Team</div></li>

我有div中的每個日期:每個列表項上的第一個,我有一個跨度中的當前日期。

我試過使用Date.js將給定的日期和今天的日期構造成可比較的格式,然後將它們相互比較並顯示最新的一個 - 但我似乎無法用更多比一個列表項目。

我想在今天的日期之前爲每個列表項添加一個「隱藏」類。

這裏是我到目前爲止有:

<?php 
$request = "https://www.kimonolabs.com/api/csv/9shgt89o?apikey=-----"; 
$response = file_get_contents($request); 
$results = json_decode($response); 
$currentdate = date("D d M y"); 
echo "<ul>\n\n"; 
$f = fopen("https://www.kimonolabs.com/api/csv/9shgt89o?apikey=-----", "r"); 
while (($line = fgetcsv($f)) !== false) { 
    echo "<li>"; 
    foreach ($line as $cell) { 
     echo "<div>" . htmlspecialchars($cell) . "</div>"; 
    } 
    echo "</li>\n"; 
    } 
fclose($f); 
echo "\n</ul>"; 
echo "<span>" . $currentdate . "</span>" 
?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'> 
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script> 
<script src="date.js"></script> 
<style> 
body { 
    font-family: 'Open Sans', sans-serif; 
} 

.hidden { 
    display:none; 
} 

ul li div { 
    display:inline-block; 
    padding:6px; 
} 

ul { 
    list-style:none; 
} 

ul li { 
    padding:6px; 
} 
</style> 
<head> 
<script> 
$(document).ready(function(){ 
    $('ul li:nth-child(1)').addClass('hidden'); 
    $('ul li:nth-child(2)').addClass('hidden'); 
    $('ul li div:nth-child(7)').addClass('hidden'); 
    $('ul li div:nth-child(8)').addClass('hidden'); 
    $('span').addClass('date'); 
}); 
var todaytext = $('span').text(); 
var today = Date.parse(todaytext); 
document.write('<p>' + today +'</p>'); 

$('ul li').each(function() { 
    Date.parse(this); 
}); 
var fixturetext = $('ul li:eq(div:first').text(); 
var fixture = Date.parse(fixturetext); 
document.write('<p>' + fixture +'</p>'); 


</script> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
</head> 

<body> 
</body> 
</html> 

我不認爲我是遙遠的答案,但我只是絆倒自己的那一刻!

在此先感謝。

+0

在您的聲明之前,您有* echo *聲明。文檔類型應該是任何HTML文檔中的第一件事。 – David

+0

究竟是什麼問題? – David

+0

嗨大衛 - 這不是一個問題,現在,這只是一個測試文件,以確保功能的工作 - 這不會活躍。 –

回答

0

應該發生在多個列表項上的事情應該在循環中進行。類似這樣的:

$('ul li').each(function() { 
    var d = Date.parse(this); 
    if(d < today) 
     this.hide(); 
}); 

PHP語句應該放在HTML正文中。

+0

我正在解析列表中div的日期,但顯然strotime工作正常,所以這是不必要的!不過,感謝您的幫助。 –

相關問題