[highlight antiquewhite] music.csv [/highlight]
1 One First one-first.mp3
2 Two Second two-second.mp3
3 Three Third three-third.mp3
[highlight antiquewhite] musiclist.php [/highlight]
<html>
<body>
<form [green]action[/green]=[maroon]"musicsend.php"[/maroon]>
<table [green]border[/green]=[maroon]"1"[/maroon]>
<tr><th>I want it</th><th>Title</th><th>Artist</th></tr>
[highlight #eee]<?php
[teal]$FIL[/teal]=fopen([maroon]"music.csv"[/maroon],[maroon]"r"[/maroon]);
[b]while[/b] ([teal]$lin[/teal]=fgetcsv([teal]$FIL[/teal],0,[maroon]"\t"[/maroon])) {
echo [maroon]"<tr><td><input type=\"checkbox\" name=\"nr[]\" value=\"[/maroon][teal]$lin[0][/teal][maroon]\"></td><td>$lin[2]</td><td>$lin[1]</td></tr>\n"[/maroon];
}
fclose([teal]$FIL[/teal]);
?>[/highlight]
</table>
<input [green]type[/green]=[maroon]"submit"[/maroon] [green]value[/green]=[maroon]"Send selection list"[/maroon]>
</form>
</body>
</html>
[highlight antiquewhite] musicsend.php [/highlight]
<html>
<body>
[highlight #eee]<?php
[teal]$lis[/teal]=[teal]$_GET[nr][/teal];
[teal]$mess[/teal]=[maroon]"Prepare the following files : "[/maroon];
echo [maroon]"You sent a list of "[/maroon],count([teal]$lis[/teal]),[maroon]" melodies :<br>\n"[/maroon];
[b]if[/b] ([teal]$lis[/teal]) {
echo [maroon]"<ol>\n"[/maroon];
[teal]$FIL[/teal]=fopen([maroon]"music.csv"[/maroon],[maroon]"r"[/maroon]);
[b]while[/b] ([teal]$lin[/teal]=fgetcsv([teal]$FIL[/teal],0,[maroon]"\t"[/maroon])) [b]if[/b] (array_search([teal]$lin[0][/teal],[teal]$lis[/teal])!==false) {
echo [maroon]"<li>[/maroon][teal]$lin[2][/teal][maroon] - [/maroon][teal]$lin[1][/teal][maroon]</li>\n"[/maroon];
[teal]$mess[/teal].=[maroon]"[/maroon][teal]$lin[3][/teal][maroon], "[/maroon];
}
fclose([teal]$FIL[/teal]);
echo [maroon]"</ol>\n"[/maroon];
mail([maroon]"you@example.com"[/maroon],[maroon]"Playlist requirement"[/maroon],[teal]$mess[/teal]);
}
?>[/highlight]
</body>
</html>