Jump to content

Can someone tell me what's wrong here?


twofish

Recommended Posts

      <?php foreach($library->getSongList() as $k => $song) { ?>
      <tr>
        <td width="60px"><input type="checkbox" name="check[]" value="<?php echo($k); ?>"></td>
        <td><?php echo $song['song']; ?></td>
        <td><?php echo $song['artist']; ?></td>
        <td><?php echo $song['genre']; ?></td>
      </tr>

 

This creates a list that lays out nicely like this:

[] Song Title | Artist | Genre

 

Upon Selection, it should echo for each selection:

# Song title | Artist | Genre

 

but instead, its just displaying

 

#

 

Is there something obvious here that I'm missing?

Link to comment
https://forums.phpfreaks.com/topic/157385-can-someone-tell-me-whats-wrong-here/
Share on other sites

Here's a snippit (cleaned up for readability):

 

[2562]=>  array(4) { ["artist"]=>  string(6) "P.O.D." ["song"]=>  string(19) "Youth Of The Nation" ["genre"]=>  string(3) "Rap" ["location"]=>  string(5) "CD171" } 

[2567]=>  array(4) { ["artist"]=>  string(11) "Cranberries" ["song"]=>  string(6) "Zombie" ["genre"]=>  string(3) "90s" ["location"]=>  string(5) "CD138" } 

[2568]=>  array(4) { ["artist"]=>  string(20) "Cherry Poppin Daddys" ["song"]=>  string(14) "Zoot Suit Riot" ["genre"]=>  string(5) "Swing" ["location"]=>  string(5) "BCD73"

 

Selecting those same songs and submitting, it just comes out with the number. 

 

 

Wouldn't that cause an infinite loop?

 

Try this -

      $songlist = $library->getSongList();
      <?php foreach($songlist as $k => $song) { ?>
      <tr>
        <td width="60px"><input type="checkbox" name="check[]" value="<?php echo($k); ?>"></td>
        <td><?php echo $song['song']; ?></td>
        <td><?php echo $song['artist']; ?></td>
        <td><?php echo $song['genre']; ?></td>
      </tr>

thanks for your help Ken!  alas, same results so far.  :( 

 

Here's the code. 

 

<?php

  include('config.php');
  include('classes.php');

  $library = new SongLibrary();
  $songlist = $library->getSongList();
  $value[] = $_POST['check'];
  $_SESSION['playlist'] = array();
?>
<html>
  <head>
    <title>Music Collection</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
  </head>
  <body>
    <form name="playlist" method="POST" action="review.php">
    <table class="navigation">
      <tr>
        <td class="sortinfo" width="60px"> </td>
        <td class="sortinfo"><a href="index.php?sort_order=desc&sort_by=title">Song</a></td>
        <td class="sortinfo"><a href="index.php?sort_order=desc&sort_by=artist">Artist</a></td>
        <td class="sortinfo"><a href="index.php?sort_order=desc&sort_by=genre">Genre</a></td>
      </tr>
    </table>

    <table class="main">
      <?php foreach($songlist as $k => $song) { ?>
      <tr>
        <td width="60px"><input type="checkbox" name="check[]" value="<?php echo($k); ?>"></td>
        <td><?php echo $song['song']; ?></td>
        <td><?php echo $song['artist']; ?></td>
        <td><?php echo $song['genre']; ?></td>
      </tr>
      <?php }?>
      
      
      var_dump($k);

      <tr>
        <td><input type="submit" value="Review Playlist" name="submit" /></td>
      </tr>
    </table>
  </body>
</html>

 

Review.php sets the following, which is where I'm getting just the numbers:

 

  $checked_boxes = implode("\n<BR>", $_POST['check']);

 

forgive my ignorance on php, i'm still very new to this world. :(

Try a stlightly different call for your song information. Instead of $song['song'] try $songlist[$k]['song'].

It may not fix anything but worth a try. I normally stick to the latter in my coding to keep the same variable for my song information throughout the page. Also try a print_r($song[$k]) in your foreach loop to debug, could be something with your variable not being set right.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.