TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-09-2008, 08:05 AM   #1 (permalink)
The Visitor
 
Join Date: Sep 2008
Posts: 2
Thanks: 0
knvuppula is on a distinguished road
Default Retrving data from database to form

Hi all

Any one can help me Regarding the query

I have the user posted data in the data base and i want to display the comments on the HTML form

But the mistake is i am able retrive the data by useing mysql_fetech_assoc using while loop but the values are not displayed on the form

Ok


My script is

<?php
global $Ans1, $Ans2, $Ans3, $Ans4, $Ans5, $comments;

$connect = mysql_connect("Localhost", "root", "") or die ("I am unable to conect with database because of".mysql_error());

$selectdb = mysql_select_db("moodledb") or die("I can't select the database because of".mysql_error());

$Join = "SELECT `mdl_al_sessionfeedback`.`sessionid`, `mdl_al_sessionfeedback`.`ans1`, `mdl_al_sessionfeedback`.`ans2`,

`mdl_al_sessionfeedback`.`ans3`, `mdl_al_sessionfeedback`.`ans4`,`mdl_al_sessionfee dback`.`ans5`,

`mdl_al_sessionfeedback`.`comments` FROM `mdl_al_sessionfeedback`, `mdl_al_sessions` WHERE (`mdl_al_sessionfeedback`.`sessionid` =
`mdl_al_sessions`.`alsessioncode`) ";

$result = mysql_query($Join) or die("Unable to execute the join query because of:".mysql_error());

$row = mysql_fetch_assoc($result);

$num = mysql_num_rows($result);

for($i=0; $i<$num; $i++)
{
$Ans1 = mysql_result($result,$i,"ans1");

$Ans2 = mysql_result($result,$i,"ans2");

$Ans3 = mysql_result($result,$i,"ans3");

$Ans4 = mysql_result($result,$i,"ans4");

$Ans5 = mysql_result($result,$i,"ans5");

$comments = mysql_result($result,$i,"comments");

echo $comments;
}
echo "<textarea name='txtComments' rows='2' cols='20' id='txtComments' value = '<?php $comments ?>'></textarea>";
?>
Narender

Last edited by knvuppula : 09-09-2008 at 08:11 AM. Reason: adding codeing
knvuppula is offline  
Reply With Quote
Old 09-09-2008, 08:48 AM   #2 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Does the <textarea> tag have a value attribute? anyway if you want data to be displayed inside a <textarea> then you do it between the opening and closing tags, in your example:
PHP Code:
echo "<textarea name='txtComments' rows='2' cols='20' id='txtComments' value = '<?php $comments ?>'></textarea>";
needs to be changed to :
PHP Code:
echo "<textarea name='txtComments' rows='2' cols='20' id='txtComments' >$comments</textarea>"
there is also no need for '<?php $comments; ?>'.

I do think the retrieving of data could be a little better, the use of both mysql_fetch_assoc and mysql_result i can't understand.
This perhaps is a better way of doing it:
PHP Code:
while ($aRow mysql_fetch_assoc($result)) 
{
     echo 
"<textarea name='txtComments' rows='2' cols='20' id='txtComments' >" .$aRow['comments']. "</textarea>";

__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 09-10-2008, 04:33 AM   #3 (permalink)
The Visitor
 
Join Date: Sep 2008
Posts: 2
Thanks: 0
knvuppula is on a distinguished road
Default Retrving values from database and displaying in a form

Hi

it displays the every time text box along with the data but i want to display only one text area and value in the text box need to be changed according to the session id

i am attaching the output how it display and what is my requirement please find the two attachments and help me

Narender
Attached Thumbnails
retrving-data-database-form-requirement.jpg  
knvuppula is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:36 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design