来自db的多行

时间:2013-12-22 20:44:51

标签: php css

我正在尝试从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
 }
}
?>

2 个答案:

答案 0 :(得分:2)

DATE是SQL中的数据类型,您需要使用反向标记

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

此外,您正在错误地访问您的行。行通常由单维数组表示,因此$ row ['content']和$ row ['Date']

答案 1 :(得分:1)

$row是包含2个字段的1维数组:内容日期

尝试,

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