SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Dec 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displaying data in dynamic form

    Hi guys,
    I am having some problems displaying data in dynamic form. It always displays the last saved data, instead of the latest one retrieved from the database.

    Here is the code to retrieve the data:-
    Code PHP:
    if(isset($_POST['edit_budget'])){
    	$travel_request=getInfoTravelBudget($_POST['edit_budget']);
    	for($b=1;$b<count($travel_request);$b++){
    		$_POST['departure']=$travel_request[$b][5];
    		$_POST['destination']=$travel_request[$b][4];
    		$_POST['departure_date']=$travel_request[$b][6];
    		$_POST['return_date']=$travel_request[$b][7];
    		$_POST['travel_mode']=$travel_request[$b][8];
    		$_POST['quantity'.$b]=$travel_request[$b][11];
    		$_POST['person_name'.$b]=$travel_request[$b][12];
    		$_POST['currency'.$b]=$travel_request[$b][13];
    		$_POST['rate'.$b]=$travel_request[$b][14];
    		$_POST['unit_price'.$b]=$travel_request[$b][15];
    		$_POST['amount'.$b]=$travel_request[$b][16];
    		$_POST['amount_total'.$b]=$travel_request[$b][17];           
    	}
    }

    And this is the code to display it:-

    Code PHP:
    for ($j = 1; $j < mysql_num_rows($result)+1; $j++){
    				print "<tr>";
    				print $_POST['quantity'.$j];
    				print "<td><input type='checkbox' id='checkbox".$j."' name='enable".$j."' value='1'  /></td>";
    				print "<td><input type='text' name='item_description".$j."' value='".$result_array['budget_item']."' /></td>";
    				print "<td><input type='text'  name='quantity".$j."' value='".$_POST['quantity'.$j]."' ".$field_status."/></td>";
    				print "<td><input type='text' name='currency".$j."'  value='".$_POST['currency'.$j]."' /></td>";
    				print "<td><input type='text' name='rate".$j."'  value='".$_POST['rate'.$j]."' /></td>";
    				print "<td><input type='text'  onkeyup='checkvalue(".$j.")' name='unit_price".$j."' value='".$_POST['unit_price'.$j]."' /></td>";
    				print "<td><input type='text' name='amount".$j."' value='".$_POST['amount'.$j]."' ".$field_status."/></td>";
    				print "<td><input type='text' name='amount_rm".$j."' value='".$_POST['amount_rm'.$j]."' /></td>";
    				print "</tr>";
    			}
    		}

    BTW I have simplified the code a little. I have also checked to make sure that the function getInfoTravelBudget return results from the db, and it does.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    The two pieces of code aren't related at all. The first loops through an array returned by a function (btw, you might as well get the latest row of the array instead of looping through it, since you do nothing with the data but saving the values in several variables). The second loops through a mysql result set, and who knows where that set comes from.
    And for both the array and the mysql result set, it isn't clear how they get the data.

  3. #3
    SitePoint Member
    Join Date
    Dec 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in the first code, the data is retrieved from the db, and saved in the appropriate $_POST variable. Then the second code is used to generate the dynamic form and the gets the $_POST value from the first code.

    I didn't include the data retrieval part as its quite long, and i have also checked to make sure that it returns data, and it does.

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Ah yes, now I see
    But still, it isn't clear to me what you mean by last saved data and the latest one retrieved from the database. You say you checked that the array returned by the function contains the data you need, but something else is being displayed?

  5. #5
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by devxtreme View Post
    Here is the code to retrieve the data:-
    Quote Originally Posted by devxtreme View Post
    I didn't include the data retrieval part

  6. #6
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,068
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by devxtreme View Post
    in the first code, the data is retrieved from the db, and saved in the appropriate $_POST variable. Then the second code is used to generate the dynamic form and the gets the $_POST value from the first code.

    I didn't include the data retrieval part as its quite long, and i have also checked to make sure that it returns data, and it does.
    If your having trouble posting the code because of links just edit the links to a format like for example: www dot sitepoint dot com
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


Bookmarks

Posting Permissions

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