| | |
Display a dynamic page in textfield
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: May 2009
Posts: 81
Reputation:
Solved Threads: 0
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:
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
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)
<?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['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.
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
Please read http://www.daniweb.com/forums/announcement17-4.html
You should paste your code in BB tags
PHP Syntax (Toggle Plain Text)
<?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]"; } ?>
•
•
Join Date: Jun 2009
Posts: 64
Reputation:
Solved Threads: 4
try this and change according to u
php Syntax (Toggle Plain Text)
<? $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>
•
•
Join Date: Oct 2007
Posts: 78
Reputation:
Solved Threads: 5
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.?>
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)
<?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:
PHP Syntax (Toggle Plain Text)
<input type="text" id="name" name="name" value="<?php echo $name; ?>">
for text area it will be like this:
•
•
•
•
<textarea><?php echo $name; ?> </textarea>
i hope you understand.
Last edited by navi17; Jun 11th, 2009 at 8:36 am.
hi
I just edited your code
so you can find solution as you want
like this you can do as per your requirement if you want fetch only one row that time no need of while loop ok
Thanks
I just edited your code
so you can find solution as you want
PHP Syntax (Toggle Plain Text)
<?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>
$entry=mysql_fetch_array($query); Thanks
"Be honest"
"Confidence is everything"
"Confidence is everything"
Semantics aside, this is the most basic PHP-MySQL example you will get:
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)
<?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 />"; } ?>
Like:
php Syntax (Toggle Plain Text)
echo '<input name="file1" value="', $row['field1'] , '" /><br />'; echo '<textarea name="field2">', $row['field2'], '</textarea>';
•
•
Join Date: May 2009
Posts: 81
Reputation:
Solved Threads: 0
•
•
•
•
Semantics aside, this is the most basic PHP-MySQL example you will get:
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.php Syntax (Toggle Plain Text)
<?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 />"; } ?>
Like:
••••php Syntax (Toggle Plain Text)
echo '<input name="file1" value="', $row['field1'] , '" /><br />'; echo '<textarea name="field2">', $row['field2'], '</textarea>';
![]() |
Similar Threads
- display records page wise PHP code I got it (PHP)
- retrieve date from database to display on web page (PHP)
- Dynamic page set up (ASP.NET)
- Dynamic Page (PHP)
- How do you only display 8 rows per page? PHP/MYSQL (PHP)
- dynamic page (ASP.NET)
- Dynamic Page? (ASP)
- set a dynamic page size for gridview? (ASP.NET)
- How to create Dynamic Page Break in HTML? (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: help on php-mysql oop
- Next Thread: Problems with Ampersands and Google Website Optimizer in Joomla CMS
Views: 658 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error file files folder form forms function functions google howtowriteathesis href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop parse paypal pdf php problem provider query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table template tutorial update updates upload url validation validator variable video web xml youtube






