XYZ adlı üyeden alıntı: mesajı görüntüle
Eğer kodlar aynı .php dosyasında ise şu şekilde dener misiniz

<?php 
try {
     $db = new PDO("mysql:host=localhost;dbname=panel;charset=utf8", "root", "");
} catch ( PDOException $e ){
     print $e->getMessage();
} ?>

<?php
function City($id){

global $db;

$CityQuery = $db->query("select * from city order by name asc");
if ( $CityQuery->rowCount() ){
     foreach( $CityQuery as $row ){?>
    
     <option <?php if($row['id']==$id){ ?> selected="selected" <?php }else{} ?> value="<?=$row['id']?>"><?=$row['name'] ?></option>
<?php }}}?>
<select>
<?php echo City(81);?>
</select>
Teşekkürler hocam.