Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Posts
    417
    Thanks
    4
    Thanked 1 Time in 1 Post

    numbered array... 1, "mysql_field_name", "Title of form field"

    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 ?

    Code:
    <?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>
    Last edited by jasonpc1; 11-17-2010 at 08:59 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •