Serenity Emmanuel
Serenity Emmanuel

Reputation: 95

How to add a link to a list in php

Hi I have a Api list that is been generated using php here is the code that is been used to generate the list

<html>
    <title> API LIST</title>
    <body>
    <?php
    $jsondata = file_get_contents("api_link");


    $json = json_decode($jsondata, true);
    $output = "<ul>";

    foreach($output['A'] as $schools){
        
        $output .= "<li>".$schools['name']."</li>";
    }
        
    $output .="</ul>";
    
    echo $output;
?>   

the list is populated successfully but how can i add a link to the list so that when a user click on one of the items it opens a particular linked page here are the ways i have tried

$output .= "<li <a href="www.google.com/name"></a>".$schools['name']."</li>";
$output .= "<li>".$schools['name']. <a href="www.google.com/name"></a>"</li>";
$output .= "<li>".$schools['name']."<a href="www.google.com/name"></a></li>";

I don't know where or how to add the a href code

Upvotes: 1

Views: 455

Answers (2)

Kunal Raut
Kunal Raut

Reputation: 2584

You just need some changes in your code.You can try for

$output .= '<a href=https://www.google.com'.$schools['name'].'><li>'.$schools['name'].'</li></a>';

As per the comments you can use . to concatenate(join) the string and variable in php.

Upvotes: 0

Kongulov
Kongulov

Reputation: 1171

Use

$output .= '<li><a href="www.google.com/name">'.$schools['name'].'</a></li>';

Upvotes: 1

Related Questions