php - select the name as selected in dropdown -


query select god god table

$sth =$dbh->prepare("select god_id,god_name_ml,god_name_en,image,info_ml,info_en,details_ml,        details_en,rounds_ml,rounds_en,mantra_ml,mantra_en,display_order god");        $sth->execute(); 

query select deity deity table.here god_id foreign key god table

   $stmt = $dbh->prepare("select deity_id,god_id,deity_name_ml,deity_name_en,info_ml,info_en,details_ml,       details_en,mantra_ml,mantra_en,display_order deity       deity_id = :deity_id");     $stmt->bindvalue(':deity_id',$deity_id,pdo::param_int);     $stmt->execute();     $result = $stmt->fetchall();     $temp_array=$result[0];     $god_id=$temp_array['god_id']; 

display code displaying god in dropdown god table

<?php while ($row = $sth->fetch(pdo::fetch_assoc)) { ?>        <option value="<?php echo $row['god_id'];?>">          <?php echo $row['god_name_en']; ?>        </option>        <?php } ?>        </option>    </select> 

what need is, in dropdown list given god_id in god table present in deity table make selected. need selected id's selected

just check both id's same or not, try :

<?php while ($row = $sth->fetch(pdo::fetch_assoc)) { ?>   <option <?php if($row['god_id'] == $god_id) { echo "selected='selected'"; } ?> value="<?php echo $row['god_id'];?>"><?php echo $row['god_name_en']; ?></option> <?php } ?> </option> </select> 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -