This is my code for a project I am working on, is there anyway to shorten this code or even put it in a function so it is not this much repetitive code. I'm learning programming, and I was unable to find a solution to fix it. Is it a while loop or something I am meant to use?
$sth=$conn->prepare("SELECT * FROM players WHERE pid = {$steamprofile['steamid']}");
$sth->execute();
$result = $sth->fetch();
if($result['rank'] == 11){
echo "<button style='background-color: #ad0521; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Godfather</button>";
}
if($result['rank'] == 10){
echo "<button style='background-color: #999900; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Mob Boss</button>";
}
if($result['rank'] == 9){
echo "<button style='background-color: #798488; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Under Boss</button>";
}
if($result['rank'] == 8){
echo "<button style='background-color: #397be5; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Warlord</button>";
}
if($result['rank'] == 7){
echo "<button style='background-color: #6f9de8; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Turf Captain</button>";
}
if($result['rank'] == 6){
echo "<button style='background-color: #c1722c; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Hitman</button>";
}
if($result['rank'] == 5){
echo "<button style='background-color: #ffbf00; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Henchman</button>";
}
if($result['rank'] == 4){
echo "<button style='background-color: #008c5f; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Loan Shark</button>";
}
if($result['rank'] == 3){
echo "<button style='background-color: #12c98c; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Enforcer</button>";
}
if($result['rank'] == 2){
echo "<button style='background-color: #6a0e91; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Butcher</button>";
}
if($result['rank'] == 1){
echo "<button style='background-color: #b94ae8; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Scout</button>";
}
if($result['rank'] == 0){
echo "<button style='background-color: #595959; width: 100%; color: white; border: 0px solid black; font-family: myFirstFont; font-size: 18px;' disabled>Guest</button>";
}