Search code examples
phpdatabasehref

Php web link href


I have made this code, and it works good, but I need how to create an link(href) on the output file. I tried several ways but i just cant, don't need an answer but some pointers where to learn.

 if ($row = mysqli_fetch_array($result)) {
     $output =  $row["id"];
 }
 if ($output) {
     echo $output; 
 }
 else { 
     echo "That is not a valid record on our database";
 }

Solution

  • You should just echo the anchor tag with your $output

    $output =  $row["title"];
    $output ='FirstSong'; #To test i am using this as FirstSong
    echo "<a href='songs?id=".$output."'>Click here</a>"; #You can have any text for href
    

    So your code will be

     if ($row = mysqli_fetch_array($result)) {
     $output =  $row["title"];
     }
     if ($output) { 
     echo "<a href='songs?id=".$output."'>Click here</a>";
     }
     else { echo "That is not a valid record on our database"; }
    

    Here is the demo