Arkadaşlar aşağıda yer alan kodlarda "favori ekle" butonu ile ajax.php den favori olarak ekliyor fakat favoriye eklenen link "favoriden çıkar" şeklinde butonun değişmesini nasıl sağlayabilirim?


$sql = "SELECT ad, subcat_name, bolum_id FROM bolumListesi LEFT JOIN tbl_subcat ON bolumListesi.id = tbl_subcat.cat_id;";
$result = $conn->query($sql);

$last_category = "";
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        $cat_name = $row["ad"];
        if ($cat_name != $last_category) {
            echo '<li style="width:100%;" class="list-group-item list-group-item-action list-group-item-primary rounded"><span class="" style="margin-top: -1px; margin-bottom: -1px; color:black; text-decoration:none; width:100%;  display:block;">'.  $cat_name .'</span></li>';

            $last_category = $cat_name;
        }
        echo '
        
        <li style="width:100%;" class="list-group-item list-group-item-action list-group-item-primary rounded"><div><a href="http://onlinesinav.gen.tr/test-sec.php?donemId='. $row["bolum_id"] .'" class="" style="margin-top: -1px; margin-bottom: -1px; color:black; text-decoration:none; width:100%;  display:block;">&nbsp;&nbsp;&nbsp;&nbsp;'. $row["subcat_name"] .'</a><a href="ajax.php?addFavorite=1&lesson_id=1&ref_url=1" style="float:right; border:1px solid #ddd; border-radius:5px; padding:3px; color:white; background-color:#00008B; text-decoration:none; margin-top:-20px; z-index:999;">Favoriye Ekle</a>';

    }
} else {
    echo '<a href="ajax.php?removeFavorite=1&lesson_id=Numara&ref_url=<?=$bolumId?>" style="float:right; border:1px solid #ddd; border-radius:5px; padding:3px; color:white; background-color:darkred; text-decoration:none; margin-top:-20px; z-index:999;">Favoriden Kaldir</a> ';
}

$conn->close();