943,775 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1317
  • PHP RSS
Jun 11th, 2009
0

Display a dynamic page in textfield

Expand Post »
Hi,
Anyone can help me?..must be easy for most of you.

instead of just displaying data from the database in a table,
i want to make it varies..some in textbox, some in text area.
this is my code:
php Syntax (Toggle Plain Text)
  1. <?php
  2. $query= mysql_query(" SELECT * FROM office
  3. WHERE officeID='" . $_GET['officeID'] . "'");
  4.  
  5. while($entry=mysql_fetch_array($query))
  6. {
  7.  
  8. echo $entry['name'];
  9. echo $entry['location'];
  10. }
  11. ?>

it dsplays correct data from the database in this format:
abc33bar avenue
which refer to (name abc, location 33bar avenue ).

how make it like this?
name : (here is the dynamic data -name- from database)
location : location

I have construct a textfield with inital value like this :
echo <input name="name" type="text" value="<?php echo $entry['name']; ?>"> ;

however it doesn't work.
thanks for your help
Last edited by peter_budo; Jun 11th, 2009 at 7:51 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
tulipputih is offline Offline
107 posts
since May 2009
Jun 11th, 2009
0

Re: Display a dynamic page in textfield

please check my thread i need help, updation there is a code for this
Reputation Points: 2
Solved Threads: 4
Junior Poster in Training
furqan219 is offline Offline
89 posts
since Jun 2009
Jun 11th, 2009
0

Re: Display a dynamic page in textfield

This is your 11th post and still you have no idea how to post source code?

Please read http://www.daniweb.com/forums/announcement17-4.html

You should paste your code in BB tags

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $query= mysql_query(" SELECT * FROM office
  3. WHERE officeID='" . $_GET['officeID'] . "'");
  4. while($entry=mysql_fetch_array($query))
  5. {
  6. echo "<br/>Name : $entry[name]";
  7. echo "<br/>Location : $entry[location]";
  8. }
  9. ?>
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jun 11th, 2009
0

Re: Display a dynamic page in textfield

try this and change according to u
php Syntax (Toggle Plain Text)
  1. <?
  2. $con = mysql_connect("localhost","root","");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7.  
  8. mysql_select_db("new", $con);
  9.  
  10. $result = mysql_query("SELECT * FROM abc
  11. WHERE SiteId='C-SIL-4441' "); // I just get one value at this time
  12.  
  13.  
  14. while($row = mysql_fetch_array($result))
  15. {
  16. echo "<table cellpadding=2 cellspacing=2 width=100%>
  17. <tr>
  18.  
  19.  
  20. </tr>";
  21. echo "<tr>";
  22. echo "<th bgcolor=#5D9BCC >SiteID</th>";
  23. echo "<td bgcolor=#FEE9A9>" . $row['SiteId'] . "</td>";
  24. echo "<td bgcolor=#FEE9A9>" . $row['Name'] . "</td>";
  25. echo "<td bgcolor=#FEE9A9>" . $row['Address'] . "</td>";
  26. echo "<td bgcolor=#FEE9A9>" . $row['City'] . "</td>"; // show value in cell
  27.  
  28.  
  29. $b =$row['SiteId'];
  30. $c =$row['Name'];
  31. $d =$row['Address'];
  32. $e =$row['City'];// store value in variabel
  33.  
  34.  
  35.  
  36. echo "</tr>";
  37.  
  38. }
  39. echo "</table>";
  40.  
  41.  
  42. mysql_close($con);
  43.  
  44. ?>
  45. <form action="update2.php" method="post">
  46. <table>
  47. <tr>
  48. <td>name</td>
  49. <td>
  50. <input type="text" name="username" id="username" value="<?php echo $c; ?>" /> </td></tr>
  51. <tr>
  52. <td>Address</td>
  53. <td>
  54. <input type="text" name="address" id="address" value="<?php echo $d; ?>"></td></tr>
  55. <tr>
  56. <td>city</td>
  57. <td>
  58. <input type="text" id="city" name="city" value="<?php echo $e; ?>">
  59. </td>
  60. </tr>
  61. <tr>
  62. <td colspan="2">
  63. <input type="submit" value="Update"/>
  64. </td>
  65. </tr>
  66. <input type="text" value="<?php echo $b; ?>" name="siteid">
  67. </table>
  68.  
  69. </body>
  70. </html><?
  71. $con = mysql_connect("localhost","root","");
  72. if (!$con)
  73. {
  74. die('Could not connect: ' . mysql_error());
  75. }
  76.  
  77. mysql_select_db("new", $con);
  78.  
  79. $result = mysql_query("SELECT * FROM abc
  80. WHERE SiteId='C-SIL-4441' "); // I just get one value at this time
  81.  
  82.  
  83. while($row = mysql_fetch_array($result))
  84. {
  85. echo "<table cellpadding=2 cellspacing=2 width=100%>
  86. <tr>
  87.  
  88.  
  89. </tr>";
  90. echo "<tr>";
  91. echo "<th bgcolor=#5D9BCC >SiteID</th>";
  92. echo "<td bgcolor=#FEE9A9>" . $row['SiteId'] . "</td>";
  93. echo "<td bgcolor=#FEE9A9>" . $row['Name'] . "</td>";
  94. echo "<td bgcolor=#FEE9A9>" . $row['Address'] . "</td>";
  95. echo "<td bgcolor=#FEE9A9>" . $row['City'] . "</td>"; // show value in cell
  96.  
  97.  
  98. $b =$row['SiteId'];
  99. $c =$row['Name'];
  100. $d =$row['Address'];
  101. $e =$row['City'];// store value in $b
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110. echo "</tr>";
  111.  
  112. }
  113. echo "</table>";
  114.  
  115.  
  116. mysql_close($con);
  117.  
  118. ?>
  119. <form action="update2.php" method="post">
  120. <table>
  121. <tr>
  122. <td>name</td>
  123. <td>
  124. <input type="text" name="username" id="username" value="<?php echo $c; ?>" /> </td></tr>
  125. <tr>
  126. <td>Address</td>
  127. <td>
  128. <input type="text" name="address" id="address" value="<?php echo $d; ?>"></td></tr>
  129. <tr>
  130. <td>city</td>
  131. <td>
  132. <input type="text" id="city" name="city" value="<?php echo $e; ?>">
  133. </td>
  134. </tr>
  135. <tr>
  136. <td colspan="2">
  137. <input type="submit" value="Update"/>
  138. </td>
  139. </tr>
  140. <input type="text" value="<?php echo $b; ?>" name="siteid">
  141. </table>
  142.  
  143. </body>
  144. </html>
Reputation Points: 2
Solved Threads: 4
Junior Poster in Training
furqan219 is offline Offline
89 posts
since Jun 2009
Jun 11th, 2009
0

Re: Display a dynamic page in textfield

PHP Syntax (Toggle Plain Text)
  1. 1.
  2. <?php
  3. 2.
  4. $query= mysql_query(" SELECT * FROM office
  5. 3.
  6. WHERE officeID='" . $_GET['officeID'] . "'");
  7. 4.
  8.  
  9. 5.
  10. while($entry=mysql_fetch_array($query))
  11. 6.
  12. {
  13. 7.
  14.  
  15. 8.
  16. echo $entry['name'];
  17. 9.
  18. echo $entry['location'];
  19. 10.
  20. }
  21. 11.?>

according to me there will be no need of while loop here. bec. here only i row is coming from database according to your condition it should be like this:


PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $query= mysql_query(" SELECT * FROM office
  4.  
  5. WHERE officeID='" . $_GET['officeID'] . "'");
  6.  
  7. $entry=mysql_fetch_array($query);
  8.  
  9. $name= $entry['name'];
  10.  
  11. $location= $entry['location'];

now result is in two variables $name and $location.

if you want to display data in the textfield then it will be like this
E.g:
PHP Syntax (Toggle Plain Text)
  1. <input type="text" id="name" name="name" value="<?php echo $name; ?>">

for text area it will be like this:

Quote ...
<textarea><?php echo $name; ?> </textarea>
same as with location.

i hope you understand.
Last edited by navi17; Jun 11th, 2009 at 8:36 am.
Reputation Points: 15
Solved Threads: 6
Junior Poster
navi17 is offline Offline
118 posts
since Oct 2007
Jun 11th, 2009
0

Re: Display a dynamic page in textfield

hi
I just edited your code
so you can find solution as you want
PHP Syntax (Toggle Plain Text)
  1.  
  2. <?php
  3. $query= mysql_query(" SELECT * FROM office
  4. WHERE officeID='" . $_GET['officeID'] . "'");
  5. ?>
  6. <table>
  7. while($entry=mysql_fetch_array($query))
  8. 6.
  9. { ?>
  10. 7. <tr>
  11. <td>Name</td>
  12. <td><?=$entry['name']?></td>
  13. </tr>
  14. <tr>
  15. <td>Location</td>
  16. <td><?= $entry['location']?></td>
  17. </tr>
  18. <?
  19. } ?>
  20. </table>
  21. <form method="post">
  22. <input type="text" name"txt_name" id="txt_name" value='<?=$entry['name']?>'>
  23. </form>
like this you can do as per your requirement if you want fetch only one row that time no need of while loop ok
$entry=mysql_fetch_array($query);
Thanks
Reputation Points: 13
Solved Threads: 15
Junior Poster in Training
Tulsa is offline Offline
77 posts
since May 2009
Jun 11th, 2009
0

Re: Display a dynamic page in textfield

Semantics aside, this is the most basic PHP-MySQL example you will get:
php Syntax (Toggle Plain Text)
  1. <?php
  2. // Connect to MySQL
  3. mysql_connect("host", "user", "pwd") or die(mysql_error());
  4. mysql_select_db("dbName") or die(mysql_error());
  5.  
  6. // Query some data from the MySQL database
  7. $sql = "SELECT field1, field2 FROM myTable";
  8. $result = mysql_query($sql) or die(mysql_error());
  9.  
  10. // Display the results of the query
  11. while($row = mysql_fetch_assoc($result)) {
  12. echo $row['field1'], " - ";
  13. echo $row['field2'], "<br />";
  14. }
  15. ?>
If you want to put the fields in <input> or <textbox> tags, simply alter the echo statements on lines #12 and #13 to reflect what you want to print.
Like:
php Syntax (Toggle Plain Text)
  1. echo '<input name="file1" value="', $row['field1'] , '" /><br />';
  2. echo '<textarea name="field2">', $row['field2'], '</textarea>';
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007
Jun 11th, 2009
0

Re: Display a dynamic page in textfield

Click to Expand / Collapse  Quote originally posted by Atli ...
Semantics aside, this is the most basic PHP-MySQL example you will get:
php Syntax (Toggle Plain Text)
  1. <?php
  2. // Connect to MySQL
  3. mysql_connect("host", "user", "pwd") or die(mysql_error());
  4. mysql_select_db("dbName") or die(mysql_error());
  5.  
  6. // Query some data from the MySQL database
  7. $sql = "SELECT field1, field2 FROM myTable";
  8. $result = mysql_query($sql) or die(mysql_error());
  9.  
  10. // Display the results of the query
  11. while($row = mysql_fetch_assoc($result)) {
  12. echo $row['field1'], " - ";
  13. echo $row['field2'], "<br />";
  14. }
  15. ?>
If you want to put the fields in <input> or <textbox> tags, simply alter the echo statements on lines #12 and #13 to reflect what you want to print.
Like:
Quote ...
php Syntax (Toggle Plain Text)
  1. echo '<input name="file1" value="', $row['field1'] , '" /><br />';
  2. echo '<textarea name="field2">', $row['field2'], '</textarea>';
Thanks Atli, You answered my question. I wanted to display the result in textbox or textarea. The dynamic data from the database was displayed before but not in proper textbox.
Reputation Points: 10
Solved Threads: 0
Junior Poster
tulipputih is offline Offline
107 posts
since May 2009
Jun 11th, 2009
0

Re: Display a dynamic page in textfield

I'm glad I could help
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: help on php-mysql oop
Next Thread in PHP Forum Timeline: Problems with Ampersands and Google Website Optimizer in Joomla CMS





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC