Murciano Posted March 7, 2010 Share Posted March 7, 2010 HI There, i have a drop-down box that calls data from MySQL, when the user selects from this it then populates a <textarea> with stored data from a column within a MySQL row, however the problem is that it is populating the textarea with all the rows rather than the content of the one selected.. here is the code 1) code for the drop-down box $query = "SELECT id,output, tempname FROM templates ORDER BY output"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $value = $row["id"]; $output = $row["output"]; $tempname = $row["tempname"]; $pairs["$value"] = $tempname; } echo create_dropdown("create_output", $pairs, "Choose Your Template"); function create_dropdown($identifier,$pairs,$firstentry) { // start dropdown list with the <select> element and title $dropdown = "<select name=\"$identifier\" method=\"post\" onchange=\"showtemplate(this.value)\">"; $dropdown .= "<option name=\"\">$firstentry</option>"; // Create the elements for inside the drop down box foreach($pairs AS $value => $tempname) { $dropdown .="<option name=\"$value\">$tempname</option>"; } //end the dropdown function and return it as html echo "</select>"; return $dropdown; } ?> <br /> <textarea cols="80" rows="20" name="content" style="background-color:#bed9ee;" id="content"> </textarea> 2) code that pulls the data from MySQL to populate the textarea $query = "SELECT output FROM templates ORDER BY id"; $result = mysql_query($query); while ($row = mysql_fetch_object($result)) { echo $output = $row->output; } the ajax code seems to be working as the data (allbeit too much) is being populated, hope someone can point me in the right direction as this has been driving me slowly insane now for almost 3 days.. Quote Link to comment https://forums.phpfreaks.com/topic/194452-problem-populating-textarea-with-stored-data-php-mysql-and-ajax/ Share on other sites More sharing options...
LeadingWebDev Posted March 7, 2010 Share Posted March 7, 2010 try this function create_dropdown($identifier,$pairs,$firstentry) { // start dropdown list with the <select> element and title $dropdown = "<select name=\"$identifier\" method=\"post\" onchange=\"showtemplate(this.value)\">"; $dropdown .= "<option value=\"\">$firstentry</option>"; // Create the elements for inside the drop down box foreach($pairs AS $value => $tempname) { $dropdown .="<option value=\"$value\">$tempname</option>"; } //end the dropdown function and return it as html echo "</select>"; return $dropdown; } Quote Link to comment https://forums.phpfreaks.com/topic/194452-problem-populating-textarea-with-stored-data-php-mysql-and-ajax/#findComment-1022767 Share on other sites More sharing options...
Murciano Posted March 7, 2010 Author Share Posted March 7, 2010 Thanks for taking the time out to help LeadingWebDev i tried the code provided by yourself in your post and the same problem remains that the text area is populated with all the rows from the selected column rather than just the row which is selected.. over the last couple of days i must have tried many permutations, worn out my php manual almost to get this thing working properly but it just wont have it at all... Quote Link to comment https://forums.phpfreaks.com/topic/194452-problem-populating-textarea-with-stored-data-php-mysql-and-ajax/#findComment-1022778 Share on other sites More sharing options...
LeadingWebDev Posted March 7, 2010 Share Posted March 7, 2010 what exactly u need to do? to select option that is selected for people? Quote Link to comment https://forums.phpfreaks.com/topic/194452-problem-populating-textarea-with-stored-data-php-mysql-and-ajax/#findComment-1022781 Share on other sites More sharing options...
Murciano Posted March 7, 2010 Author Share Posted March 7, 2010 the <textarea> that is to be populated will be the CKeditor (if everything works ok that is). I have a table (named templates) on the database that contains id tempname =(the name in the drop-down list) output = (stored information to populate the CKeditor textfield on select) the plan is that the user selects from the dropdown and the CKeditor textarea is then populated with the output field from MySQl, this is then edited and on submit is then stored in another table for retrieval as html source when needed.. Quote Link to comment https://forums.phpfreaks.com/topic/194452-problem-populating-textarea-with-stored-data-php-mysql-and-ajax/#findComment-1022783 Share on other sites More sharing options...
PFMaBiSmAd Posted March 7, 2010 Share Posted March 7, 2010 Assuming the HTTP request that AJAX makes does send the correct value/id, you would need to use that value in a WHERE clause in your query so that only the corresponding row would be returned and output in the AJAX response. What method does your AJAX use to send values, GET or POST, and what is the name of the get/post parameter that is used? Quote Link to comment https://forums.phpfreaks.com/topic/194452-problem-populating-textarea-with-stored-data-php-mysql-and-ajax/#findComment-1022785 Share on other sites More sharing options...
Murciano Posted March 7, 2010 Author Share Posted March 7, 2010 @PFMaBiSmAd you will not believe this, i commented out the ajax parameter (which is a GET request) to try fixing things another way, i have just removed the comment and ran it again and its gone and worked perfectly, im inclined to think that maybe LWD's code snippet earlier on in this thread may have helped because the last few hours have been an absolute pain, thankfully now that is over and i can sleep tonight..phew..thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/194452-problem-populating-textarea-with-stored-data-php-mysql-and-ajax/#findComment-1022788 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.