Marcellinus Okeke - 2013-08-01 00:57:24
I have some sets of form elements created dynamically which I use on page creation.
<?php for ($i=0;$i<6;$i++){ ?>
<div id="hold">
<input type="text" name="slinks<?php echo $i; ?>" value="<?php echo $slinks[$i]; ?>" placeholder="Input Link Name" />
<select name="cat<?php echo $i; ?>">
<option value="" selected="selected">Select Category</option>
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option value="3">Item 3</option>
</select>
<div class="clear"></div>
</div>
<?php } ?>
I am able to insert the values into my MySQL database. I want to populate values into these fields on page edit. My problem is how to bind values into the form elements assuming my database fetched sample values as:
<?php
$query = $dhb->prepare("SELECT * FROM table2 WHERE $col = ?");
$query->execute(array($id));
$amt = $query->rowCount();
$rows = $query->setFetchMode(PDO::FETCH_NUM);
while($z = $query->fetch()){
print_r($z);
}
?>
And the output from print_r()
Array
(
[0] => 3
[1] => Item3
)
Array
(
[1] => 1
[2] => Item1
)
Array
(
[0] => 2
[1] => Item2
)