954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Display a dynamic page in textfield

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
   $query= mysql_query(" SELECT * FROM office
   					WHERE officeID='" . $_GET['officeID'] . "'");
   
      while($entry=mysql_fetch_array($query))
      {
	  
      echo $entry['name'];
      echo $entry['location']; 
}
?>


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 ;

however it doesn't work.
thanks for your help

tulipputih
Junior Poster
107 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

please check my thread i need help, updation there is a code for this

furqan219
Junior Poster in Training
89 posts since Jun 2009
Reputation Points: 2
Solved Threads: 4
 

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
     $query= mysql_query(" SELECT * FROM office
                     WHERE officeID='" . $_GET['officeID'] . "'");
    while($entry=mysql_fetch_array($query))
            {
             echo  "<br/>Name : $entry[name]";
              echo "<br/>Location : $entry[location]";
             }
?>
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

try this and change according to u

<?
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("new", $con);

$result = mysql_query("SELECT * FROM abc
WHERE SiteId='C-SIL-4441' "); // I just get one value at this time


while($row = mysql_fetch_array($result))
  {
  echo "<table cellpadding=2 cellspacing=2 width=100%>
<tr>


</tr>";
  echo "<tr>";
  echo "<th bgcolor=#5D9BCC >SiteID</th>";
  echo "<td bgcolor=#FEE9A9>" . $row['SiteId'] . "</td>";
  echo "<td bgcolor=#FEE9A9>" . $row['Name'] . "</td>";
  echo "<td bgcolor=#FEE9A9>" . $row['Address'] . "</td>";
  echo "<td bgcolor=#FEE9A9>" . $row['City'] . "</td>"; // show value in cell

 
 $b =$row['SiteId']; 
  $c =$row['Name'];
   $d =$row['Address'];
    $e =$row['City'];// store value in variabel
 


  echo "</tr>";
 
  }
echo "</table>";


mysql_close($con);

?>
<form action="update2.php" method="post">
<table>
<tr>
<td>name</td>
<td>
<input type="text" name="username" id="username" value="<?php echo $c; ?>" /> </td></tr>
<tr>
<td>Address</td>
<td>
<input type="text" name="address" id="address" value="<?php echo $d; ?>"></td></tr>
<tr>
<td>city</td>
<td>
<input type="text" id="city" name="city" value="<?php echo $e; ?>">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Update"/>
</td>
</tr>
<input type="text" value="<?php echo $b; ?>" name="siteid">
</table>

</body>
</html><?
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("new", $con);

$result = mysql_query("SELECT * FROM abc
WHERE SiteId='C-SIL-4441' "); // I just get one value at this time


while($row = mysql_fetch_array($result))
  {
  echo "<table cellpadding=2 cellspacing=2 width=100%>
<tr>


</tr>";
  echo "<tr>";
  echo "<th bgcolor=#5D9BCC >SiteID</th>";
  echo "<td bgcolor=#FEE9A9>" . $row['SiteId'] . "</td>";
  echo "<td bgcolor=#FEE9A9>" . $row['Name'] . "</td>";
  echo "<td bgcolor=#FEE9A9>" . $row['Address'] . "</td>";
  echo "<td bgcolor=#FEE9A9>" . $row['City'] . "</td>"; // show value in cell

 
 $b =$row['SiteId']; 
  $c =$row['Name'];
   $d =$row['Address'];
    $e =$row['City'];// store value in $b
 



  
 
  

  echo "</tr>";
 
  }
echo "</table>";


mysql_close($con);

?>
<form action="update2.php" method="post">
<table>
<tr>
<td>name</td>
<td>
<input type="text" name="username" id="username" value="<?php echo $c; ?>" /> </td></tr>
<tr>
<td>Address</td>
<td>
<input type="text" name="address" id="address" value="<?php echo $d; ?>"></td></tr>
<tr>
<td>city</td>
<td>
<input type="text" id="city" name="city" value="<?php echo $e; ?>">
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Update"/>
</td>
</tr>
<input type="text" value="<?php echo $b; ?>" name="siteid">
</table>

</body>
</html>
furqan219
Junior Poster in Training
89 posts since Jun 2009
Reputation Points: 2
Solved Threads: 4
 
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.?>


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

      $query= mysql_query(" SELECT * FROM office

      WHERE officeID='" . $_GET['officeID'] . "'");
  
    $entry=mysql_fetch_array($query);

    $name= $entry['name'];

      $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 thisE.g:

<input type="text" id="name" name="name" value="<?php echo $name; ?>">


for text area it will be like this:<?php echo $name; ?>

same as with location.

i hope you understand.

navi17
Junior Poster
118 posts since Oct 2007
Reputation Points: 15
Solved Threads: 6
 

hi
I just edited your code
so you can find solution as you want

<?php
      $query= mysql_query(" SELECT * FROM office
      WHERE officeID='" . $_GET['officeID'] . "'");
     ?>      
    <table>
      while($entry=mysql_fetch_array($query))
   6.
      { ?>
   7. <tr>
      <td>Name</td>
       <td><?=$entry['name']?></td>
      </tr>
      <tr>
     <td>Location</td>
     <td><?= $entry['location']?></td>
    </tr>
     <?   
       } ?>
</table>
 <form method="post">
<input type="text" name"txt_name" id="txt_name" value='<?=$entry['name']?>'>
 </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

Tulsa
Junior Poster in Training
77 posts since May 2009
Reputation Points: 13
Solved Threads: 15
 

Semantics aside, this is the most basic PHP-MySQL example you will get:

<?php
// Connect to MySQL
mysql_connect("host", "user", "pwd") or die(mysql_error());
mysql_select_db("dbName") or die(mysql_error());

// Query some data from the MySQL database
$sql = "SELECT field1, field2 FROM myTable";
$result = mysql_query($sql) or die(mysql_error());

// Display the results of the query
while($row = mysql_fetch_assoc($result)) {
    echo $row['field1'], " - ";
    echo $row['field2'], "";
}
?>

If you want to put the fields in or tags, simply alter the echo statements on lines #12 and #13 to reflect what you want to print.
Like:

echo '<input  name="file1" value="', $row['field1'] , '" />';
echo '<textarea name="field2">', $row['field2'], '</textarea>';
Atli
Posting Pro
540 posts since May 2007
Reputation Points: 93
Solved Threads: 70
 

Semantics aside, this is the most basic PHP-MySQL example you will get:

<?php
// Connect to MySQL
mysql_connect("host", "user", "pwd") or die(mysql_error());
mysql_select_db("dbName") or die(mysql_error());

// Query some data from the MySQL database
$sql = "SELECT field1, field2 FROM myTable";
$result = mysql_query($sql) or die(mysql_error());

// Display the results of the query
while($row = mysql_fetch_assoc($result)) {
    echo $row['field1'], " - ";
    echo $row['field2'], "";
}
?>

If you want to put the fields in or tags, simply alter the echo statements on lines #12 and #13 to reflect what you want to print. Like:

echo '<input  name="file1" value="', $row['field1'] , '" />';
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.

tulipputih
Junior Poster
107 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

I'm glad I could help :)

Atli
Posting Pro
540 posts since May 2007
Reputation Points: 93
Solved Threads: 70
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You