Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    133
    Thanks
    0
    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>";

    $n=0;

    while ($n<20) {
    $x=$master[$n];
    echo $x;
    $x=substr($x,0,6);

    $year="19".substr($x,0,2);

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

    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>";

    $n++;
    }

    echo "</ol>";

    $mysqli->close();




    ?>
    </div>

    <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 

    </table>
    Last edited by Suwannee_guy; 05-12-2014 at 06:42 PM.

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    363
    Thanks
    0
    Thanked 18 Times in 18 Posts
    PHP Code:
    $master[$x]['title']=$title
    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)
    Code:
    $other_variable[$n]['title']=$title;
    
    # ...
    
    <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
    •