Display a dynamic page in textfield

Thread Solved

Join Date: May 2009
Posts: 81
Reputation: tulipputih is an unknown quantity at this point 
Solved Threads: 0
tulipputih tulipputih is offline Offline
Junior Poster in Training

Display a dynamic page in textfield

 
0
  #1
Jun 11th, 2009
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:
  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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 64
Reputation: furqan219 has a little shameless behaviour in the past 
Solved Threads: 4
furqan219 furqan219 is offline Offline
Junior Poster in Training

Re: Display a dynamic page in textfield

 
0
  #2
Jun 11th, 2009
please check my thread i need help, updation there is a code for this
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,721
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 501
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Display a dynamic page in textfield

 
0
  #3
Jun 11th, 2009
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

  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. ?>
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 64
Reputation: furqan219 has a little shameless behaviour in the past 
Solved Threads: 4
furqan219 furqan219 is offline Offline
Junior Poster in Training

Re: Display a dynamic page in textfield

 
0
  #4
Jun 11th, 2009
try this and change according to u
  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>
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 78
Reputation: navi17 is an unknown quantity at this point 
Solved Threads: 5
navi17 navi17 is offline Offline
Junior Poster in Training

Re: Display a dynamic page in textfield

 
0
  #5
Jun 11th, 2009
  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:


  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:
  1. <input type="text" id="name" name="name" value="<?php echo $name; ?>">

for text area it will be like this:

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

i hope you understand.
Last edited by navi17; Jun 11th, 2009 at 8:36 am.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 77
Reputation: Tulsa is an unknown quantity at this point 
Solved Threads: 15
Tulsa's Avatar
Tulsa Tulsa is offline Offline
Junior Poster in Training

Re: Display a dynamic page in textfield

 
0
  #6
Jun 11th, 2009
hi
I just edited your code
so you can find solution as you want
  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
"Be honest"
"Confidence is everything"
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 455
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training

Re: Display a dynamic page in textfield

 
0
  #7
Jun 11th, 2009
Semantics aside, this is the most basic PHP-MySQL example you will get:
  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:
  1. echo '<input name="file1" value="', $row['field1'] , '" /><br />';
  2. echo '<textarea name="field2">', $row['field2'], '</textarea>';
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 81
Reputation: tulipputih is an unknown quantity at this point 
Solved Threads: 0
tulipputih tulipputih is offline Offline
Junior Poster in Training

Re: Display a dynamic page in textfield

 
0
  #8
Jun 11th, 2009
Originally Posted by Atli View Post
Semantics aside, this is the most basic PHP-MySQL example you will get:
  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:
  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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 455
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training

Re: Display a dynamic page in textfield

 
0
  #9
Jun 11th, 2009
I'm glad I could help
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 658 | Replies: 8
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC