简体   繁体   English

来自数据库的多行

[英]Multiple rows from db

I'm trying to echo out multiple rows from a sql database, but I get the error Warning. 我正在尝试从sql数据库中回显多行,但出现错误警告。 Illegal string offset 'Date' In.... 非法的字符串偏移量'Date'In ....

$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
 }
}
?>

DATE is a datatype in SQL, you need to escape it with back ticks DATE是SQL中的数据类型,您需要使用反斜杠对其进行转义

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

Also, you're accessing your row incorrectly. 另外,您访问的行不正确。 Rows are typically represented by a uni-dimensional array, so $row['content'] and $row['Date'] 行通常由一维数组表示,因此$ row ['content']和$ row ['Date']

$row is 1-dimensional array with 2 fields: content and Date . $row是一维数组,具有2个字段: contentDate

Try, 尝试,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM