I'm using a function that returns a Fetched Array from a Database ( PDO::fetch(PDO::FETCH_ASSOC) ).
this function returns A LOT OF COLUMNS and when I am editing all those columns in a Form, obviously I need the fields to be populate with the current data.
Code (modified for the question):
//returns something like $owner["name"], $owner["lastname"],
//$owner["phone1"] ... and 53 fields more.
$owner = controllerGetOnwer($ownerID);
//So I used a foreach to create VARIABLE VARIABLES
foreach($owner as $key=>$value) {
${$key} = $value; //you get something like $name = <what is in that column>
}
I am gonna use this form in a lot of pages, not only for owners, but also for customers, administrators, and so on... That's why I decided to put the form in a function inside a static class I already used to 'render' all the HTML I will use a lot of times (such as Headers, logos, menus, etc)
//This is inside the HTMLRenderClass
renderTheEditForm() {
?>
<form>
Name: *<br/>
<input type="text" name="personalname" value="<?php if(isset($name)) echo $name; ?>"/><br/><br/>
Last Name: *<br/>
<input type="text" name="personallastname" value="<?php if(isset($lastname)) echo $lastname; ?>"/><br/><br/>
Phone Number 1:<br/>
<input type="text" name="personalphone1" value="<?php if(isset($phone1)) echo $phone1; ?>"/><br/><br/>
<!-- AND 53 FIELDS MORE -->
</form>
<?PHP
}
All the variables that you see inside the VALUE attribute are the same as the ones that are being created dinamically in the FOREACH. When I paste the form HTML code below the Foreach, I can see the data being loaded, but when I use the Function from the HTMLRenderClass I get nothing... I haven't been able to find the reason.
I hope I explained well, thanks beforehand!
extract()](php.net/manual/en/function.extract.php) not work?name,valueandlabeland generating the HTML with PHP in a loop?