So; I`m a PHP noob and I’m trying to get a website to work, as a fun side-project. I currently have a database with lyrics, and who sung those lyrics etc. Now I echo these onto LYRICS.PHP with the following code:
Functions.php
function getLyric() {
(int)$id = $_GET['id'];
$query = mysql_query("SELECT * FROM lyrics WHERE id = ".$id."") or die(mysql_error());
while ($row = mysql_fetch_assoc($query)) { ?>
<h1><?= $row['title']; ?> lyrics</h1>
<h2><?= $row['author']; ?></h2>
<pre><?= $row['lyrics']; ?></pre>
<?php }
}
Lyrics.php?id=1
<?php getLyric(); ?>
Which works, but how do I display the singer and name of the song in the [title] tag of the page? (currently it’s just plain html). With how I design it right now I don’t think that is possible right?
It depends on how you’re outputting the HTML. If you are using inline HTML in
lyrics.php, then you can do something like:If you are echoing a string of HTML, then you can do something like:
Obviously you need to make the
getTitlefunction first.