kfarrar Posted December 13, 2010 Share Posted December 13, 2010 I have a page where a user builds a custom form line by line by selecting a variety of “form elements” on a self submitting page. These form elements are just HTML tables with multiple <input type=”text”> or <textarea>’s which are stored in the MySQL database. Once the user has built the form then they fill in the text areas of each line and save the completed form. The data from each line is saved to the database. The problem is I can’t seem to populate the text areas on the form for viewing because my form inputs have a variable for value=”$example”. EXAMPLE: If this was on my page of code it will work and echo the contents of field1 into the text area. <textarea name="line_item[]"><?echo $got->field1;?></textarea> But when the same html as above comes from the database then the text area is populated with this <?echo $got->field1;?> What do I do? Here is the PHP that echo’s the form: $query = ("SELECT * FROM auto_save ORDER BY line_order ASC"); $result = mysql_query($query) or die(mysql_error()); $line_order = 1.0; while($row = mysql_fetch_array($result)) { $get_one = mysql_query("SELECT * FROM auto_save WHERE line_order = $line_order"); $got = mysql_fetch_object($get_one); //echo "$got->field1 $got->field2 $got->field3 $got->field4 $got->field5"; echo '<table><tr><td width=50 class=linenumber>'.$row['line_order'].'</td><td>'.$row['form'].'</td></tr></table>'; $line_order = $line_order + 1.0; } Quote Link to comment Share on other sites More sharing options...
joel24 Posted December 13, 2010 Share Posted December 13, 2010 you're only retrieving one row from the DB. you need to use a while loop to cycle through all the returned DB rows. i.e.look here $result = mysql_query("select * from mytable"); while ($row = mysql_fetch_object($result)) { echo $row->user_id; echo $row->fullname; } Quote Link to comment Share on other sites More sharing options...
kfarrar Posted December 14, 2010 Author Share Posted December 14, 2010 Thanks for the reply. mysql_fetch_object was inside the While loop so it was working as needed. Turns out the solution was to use the eval construct to interpert the html called from the database as code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.