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

however it doesn't work.
thanks for your help

Recommended Answers

All 8 Replies

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

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]";
             }
?>

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>
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 this
E.g:

<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.

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

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'], "<br />";
}
?>

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:

echo '<input  name="file1" value="', $row['field1'] , '" /><br />';
echo '<textarea name="field2">', $row['field2'], '</textarea>';

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'], "<br />";
}
?>

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:

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

I'm glad I could help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.