twofish Posted May 8, 2009 Share Posted May 8, 2009 <?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 More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 What does $library->getSongList() return? var_dump($library->getSongList()); Link to comment https://forums.phpfreaks.com/topic/157385-can-someone-tell-me-whats-wrong-here/#findComment-829656 Share on other sites More sharing options...
twofish Posted May 8, 2009 Author Share Posted May 8, 2009 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. Link to comment https://forums.phpfreaks.com/topic/157385-can-someone-tell-me-whats-wrong-here/#findComment-829702 Share on other sites More sharing options...
Ken2k7 Posted May 8, 2009 Share Posted May 8, 2009 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> Link to comment https://forums.phpfreaks.com/topic/157385-can-someone-tell-me-whats-wrong-here/#findComment-829714 Share on other sites More sharing options...
twofish Posted May 8, 2009 Author Share Posted May 8, 2009 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. Link to comment https://forums.phpfreaks.com/topic/157385-can-someone-tell-me-whats-wrong-here/#findComment-829729 Share on other sites More sharing options...
twofish Posted May 10, 2009 Author Share Posted May 10, 2009 I'm still stumped. Link to comment https://forums.phpfreaks.com/topic/157385-can-someone-tell-me-whats-wrong-here/#findComment-830940 Share on other sites More sharing options...
gamer10101 Posted May 10, 2009 Share Posted May 10, 2009 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. Link to comment https://forums.phpfreaks.com/topic/157385-can-someone-tell-me-whats-wrong-here/#findComment-830941 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.