Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Thanked 0 Times in 0 Posts

    Displaying same value in two columns

    Ooops. My bad. Posted to wrong forum.
    Please move.

    I can not understand why I am getting an illegal string offset error message.
    I create an array and display the contents in the left column.
    In the right column, I want to display the value from the first item in the array.

    array[0] displays fine in the left column.
    array[0]['a'] gives me the error.
    Please explain why.
    How do I do it correctly?

    PHP Code:

    echo "<ol>";


    while ($n<20) {
    echo $x;


    $sql = "SELECT * FROM picker where songID='$x'";
    $result = $mysqli->query($sql);
    $row = $result->fetch_assoc(); 

    echo "<br>";

    echo "<a href=\"javascript:ajaxpage('http://mroldies.net/radio/ajax.php','bcol');\" data-src='http://mroldies.net/audio/$year/$x.mp3'>";
    echo "<li>";
    echo $title."<br>";
    echo $artist." - ".$year;

    echo "</li>\n";
    echo "</a>";


    echo "</ol>";



    <div id="bcol">

    <?php  echo $master[0]; ?>
    // works fine displays value as in the array.

    <table border="1">
    <tr><td>Title</td><td><?php echo $master[0]['title']; ?></td></tr>

    // this generates the offset error message 

    Last edited by Suwannee_guy; 05-12-2014 at 07:42 PM.

  2. #2
    Regular Coder
    Join Date
    Oct 2004
    Thanked 26 Times in 26 Posts
    PHP Code:
    You're using $x so it will be the id, eg. $master[123456]['title'], not $n.

    I suggest you use a different variable (so you don't overwrite what you already have)
    # ...
    <tr><td>Title</td><td><?php echo $other_variable[0]['title']; ?></td></tr>


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts