PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
function pickmusic() {
global $cook, $dbname, $menupage, $dbname, $table, $menupage, $musicpage, $addmusicpage, $addmusicpageform, $cookiepage, $deletemusicpage, $deletemusicpageform, $loop, $autostart, $visible;
return "<center>Please select what song you would like to play.<form method="post" action="".$cookiepage.""><select name="dropdown"><option value="none" selected>None</option><option value="none">----------------</option>";
if ($db = sqlite_open($dbname, 0666, $sqliteerror)){ //Tries to open the database.
$result = sqlite_query($db, "select cookiename from $table ORDER BY artist, songname"); //Gets all of the music from the database, ordered first by Arist, then by songname
while ($row=sqlite_fetch_array($result)) {
$moo = $row['cookiename'];
$result2 = sqlite_query($db, "select * from $table where cookiename = '$moo'");//Gets the information from the database where the cookiename is that of the one stored in the cookie
$result2 = sqlite_fetch_array($result2);
return "<option value="".$row['cookiename']."">".stripslashes($result2['artist'])." - ".stripslashes($result2['songname'])."</option>";
}//Closes the while statement (By default, its on line 13)
?>
return "</select><br><input type="submit" name="Submit" value="Submit">
<?php
} else {
die ($sqliteerror);//If the database could not be opened, it will return this error
}//Closes the database opening if statement (By default, its on line 11)
}
Assign as many lines of code to a variable, then return it.
The dirty solution - and it's quite dirty, I find - is to use heredoc for multiple lines of text.
e.g.
return <<<dirtydirtydirty This is what I want to return, and it's a river of no return and Marilyn Monroe is in it as well and she sings a song about a river of no return and she has no clue about life on the frontier but the she still sings the song of the river of no return
dirtydirtydirty;
Now I have to go wash my hands
Why you would want to use heredoc is beyond me - assigning stuff to a variable is makes life much, much nicer. Cleaner. Better.
Actually, I have a problem. I am wanting to print HTML though a function, but it uses a while statement. There are things I want to happen both before and after the while statement. I think I am screwed, no?