I'm trying to create a simple program where a user enters the name of a song, and gives it a rating (out of 5), and it displays the output first by song rating then (if the ratings are the same) displays it by the name of the song alphabetically. The idea in practice would work like this...user enters:
Song Name: My Song
Rating: 3
Song Name: His Song
Rating: 5
Song Name: Her Song
Rating: 5
Your list so far is:
Her Song - 5 stars
His Song - 5 stars
My Song - 3 stars
I just keep undoing things and clearly I'm not getting it. I had many ideas making it so I'll show you what I wrote (which isn't much): FILE: Songs.php
Code: Select all
<?php
session_start();
?><html>
<head>
<title>Song List</title>
</head>
<body>
<form action="songs.php" method="POST">
Song: <input type="text" name="song" />
Rating: <select name="rating">
<?php
foreach (range(5, 1) as $number) {
echo "<option value=\"$number\">$number</option>";
}
echo "</select>";
?>
<input type="submit" value="Submit!" />
</form>
<?php
if (isset($_POST['song']) && isset($_POST['rating'])) {
$song = $_POST['song'];
$rating = $_POST['rating'];
$_SESSION['songlist'] = array();
$_SESSION['songrating'] = array();
$_SESSION['songlist'][] = $_POST['song'];
$_SESSION['songrating'][] = $_POST['rating'];
echo "Your song " . $song . " is rated " . $rating . " stars!";
} else {
$song = NULL;
$rating = NULL;
}
print_r($_SESSION['songlist']);
?>
</body>
</html>Thank you so much for the help!