...

View Full Version : numbered array... 1, "mysql_field_name", "Title of form field"



jasonpc1
11-17-2010, 08:07 PM
Can someone please help me with an array problem i can not figure out.

I need the array to be numbered from 1 to how ever many fields that are needed in the form and have a mysql field name and the title of the field also in the array.

1, "mysql_field_name", "Title of form field"
2, "", ""

and so on

then the form will be shown based on the array.

I have the following draft code which I am working with.

any suggestions on how i may do this array ?



<?php
$options = array(
'1'=> array('fieldtext'=>'option1', 'mysqlfield'=>'option1'),
'2'=> array('fieldtext'=>'option2', 'mysqlfield'=>'option2'),
'3'=> array('fieldtext'=>'option3', 'mysqlfield'=>'option3'),
'4'=> array('fieldtext'=>'option4', 'mysqlfield'=>'option4'),
);


// $options = array(1 => "option1", "option2", "option3", "option4");

// the line above works but i want to include the name of the mysql field as well.

$userid = 1;

?>
<div style="align: center; margin: 12px; font-family:Tahoma;">
<br><br><?php
if ($_POST['Update'] != "Update") { // check if form submitted yet, if not get data from mysql.
$res = db_query("SELECT * FROM `users` WHERE `userid` = '" . $userid . "'");
foreach($options as $key => $value) { $_POST[$key] = mysql_result($res, 0, $value); }
$ok_to_update = "no";
} elseif ($_POST['Update'] == "Update") { // check if form submitted yet, if so get POST data.
// error checking
// foreach($options as $key => $value) {
// $_POST[$i] = "";
// }
$ok_to_update = "yes";
}

if ($_POST['Update'] == "Update" && $ok_to_update == "yes") {
// $res = db_query("INSERT INTO `users` () VALUES ()"); // add user details to database.
?><p><br><br><br>Thank you for updating</p><?php
} else {
?><form name="form1" method="post" action="">
<?php foreach($options as $key => $value) {
?><p><?php echo($value); ?>:&nbsp;<input type="text" name="<?php echo($key); ?>" value="<?php echo($_POST[$key]);?>"></p>
<?php } ?>
<input name="Update" type="submit" value="Update">
</form>
<?php } ?>
</div>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum