2013-12-22 45 views
0

我想從sql數據庫中回顯出多行,但我得到了錯誤警告。非法串偏移「日期」在....從數據庫的多行

$channel_check = mysql_query("SELECT content, Date FROM wgo WHERE Posted_By='$user' ORDER by `id` DESC;"); 
    $numrows_cc = mysql_num_rows($channel_check); 
    if ($numrows_cc == 0) { 
echo ''; 

// They don't have any channels so they need to create one?><h4> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspYou haven't posted anything yet. You can post what's going on in your life, how you're feeling, or anything else that matters to you.</h4> 


<?php 
} 
else 
{ 
?> 
<div id="recentc"> 
</div> 
<?php 
echo"<h2 id='lp'> Latest Posts</h2>"; 
    while($row = mysql_fetch_array($channel_check)) { 
    $channel_name = $row['content']['Date']; 
?> 
<div style="margin-top:60px;"> 
<hr style="margin-right:340px;width:600px; opacity:0;"> 

      <?php echo "<div id='rpc'><h6> $channel_name</h6></div>";?> 
    </div> 
<?php 
} 
} 
?> 
+0

旁白:到一個標題向右移動,它會更好地使用CSS而不是非中斷空格的長列表,但如果你_have_使用後者,'  '最後需要一個分號。 – halfer

回答

1

$row是1維陣列具有2個字段:內容日期

嘗試,

while ($row = mysql_fetch_array($channel_check)) { 
    print_r($row); 
    //$channel_name = $row['content']['Date']; 
+0

它的工作原理除了:adsff Array([content] => adfasdf [Date] => 2013-12-22)整個文本出現在我的網站上,而不僅僅是adfasdf - 2013-12-22 – user3127829

+0

修復它:解決方案== while($ row = mysql_fetch_array($ channel_check)){ $ channel_name = $ row ['content']; $ channel_name2 = $ row ['Posted_By']; $ channel_name3 = $ row ['Date']; – user3127829

2

日期是SQL數據類型,你需要逃避它帶回蜱

SELECT content, `Date` FROM wgo WHERE Posted_By='$user' ORDER by `id` DESC 

此外,你錯誤地訪問您的行。行通常由一維陣列表示,所以$行[「內容」]和$行[「日期」]

+0

'DATE' is ** NOT ** a reserved word => http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html –

+0

我認爲任何你不能逃避的詞或劃定保留字,DATE是其中之一,但這是個人意見。但是,你是正確的,它不在列表中,回答編輯。 – Zarathuztra

+0

這是一個經典案例,剛剛彈出不太多分鐘前實際=> http://stackoverflow.com/questions/20733888/mysql-returning-false-when-multiple-rows-meet-where-clause –