html - How to put radio button with a php value -
i having trouble using radio button, i'm getting confuse because of output of codes. in left picture that's output like, in right picture want output that. when choose candidates both radio button can choose instead of 1 should can chosen.
here's code:
<?php $yearnow=date('y'); $dsds=$rowasa['posid']; $results = $db->prepare("select * candidates,student,school_year,partylist student.idno = candidates.idno , school_year.syearid = candidates.syearid , posid =:a , candidates.partyid = partylist.partyid , school_year.from_year $yearnow "); $results->bindparam(':a', $dsds); $results->execute(); for($i=0; $rows = $results->fetch(); $i++){ ?> //here's part confuse <input type ="radio"><input style="padding: 35px 50px 35px 80px; background:url('admin/candidates/images/<?php echo $rows['image']; ?>') no-repeat scroll 5px 7px / 70px auto rgba(0, 0, 0, 0);" value="<?php echo $rows['candid'] . "-" ." ". $rows['lastname'] .",". " ". $rows['firstname'] ?>"><?php echo $rows['lastname'] ?>, <?php echo $rows['firstname'] ?> - <?php echo $rows['party_name']?> <?php } ?>
it looks sql query giving right results using joins
. regardless, im assuming sql results this:
$candidates = array( array( "id" => "1", "firstname" => "john", "image" => "some/image/path", "party_name" => "party1", ), array( "id" => "2", "firstname" => "jane", "image" => "some/image/path", "party_name" => "party2", ) );
to iterate through , build html, lot easier use foreach
so:
<form method="post" action="submit.php"> <?php foreach ($candidates $candidate) { ?> <div class="box"> <div class="image"> <img src="admin/candidates/images/<?php echo $candidate['image']; ?>" alt=""> </div> <div class="input"> <input type="radio" name="candidate_selected" value="<?= $candidate['id'] ?>"> </div> <div class="text"> <?php echo $candidate['firstname'] . " - " . $candidate['party_name'] ?> </div> </div> <?php } ?> <input type="submit"> </form>
notice how input
has same name , id
of candidate results. once submitted, should see id
of selected candidate in submit.php
handler.
now add css:
.box { display: inline-block; text-align: center; } .box .image { padding: 15px; } .box .image img { width: 150px; height: 150px; display: block; }
hope helps.
Comments
Post a Comment