0

I'm trying to echo out multiple rows from a sql database, but I get the error Warning. Illegal string offset '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
 }
}
?>
1
  • Aside: to shift a title to the right, it'd be better to use CSS rather than long lists of non-breaking spaces, but if you have to use the latter, &nbsp; requires a semi-colon at the end. Commented Dec 22, 2013 at 20:48

2 Answers 2

2

DATE is a datatype in SQL, you need to escape it with back ticks

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']

Sign up to request clarification or add additional context in comments.

9 Comments

I consider any word you can't use without escaping or delimiting a reserved word, DATE being one of them, but that's personal opinion. However, you are correct that it's not on that list, answer edited.
Here's a classic case that just popped up not too many minutes ago actually => stackoverflow.com/questions/20733888/…
I know the problem has to do with this : $row['content']['Date']; because when I do $row ['Date'], it echos the dates, and when I do $row['content'] It echos the content but it can't do both when I do $row['content']['Date']
It's a uni-dimensional array, not a multidimensional array as you are addressing it.
|
1

$row is 1-dimensional array with 2 fields: content and Date.

Try,

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

2 Comments

It works except : adsff Array ( [content] => adfasdf [Date] => 2013-12-22 ) that entire text comes out on my website, not just adfasdf - 2013-12-22
Fixed it: Solution == while($row = mysql_fetch_array($channel_check)) { $channel_name = $row['content']; $channel_name2 = $row['Posted_By']; $channel_name3 = $row['Date'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.