Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

from query to text box

Status
Not open for further replies.

thumbelina

Programmer
Jun 4, 2001
58
CA
If I get results back from a query when a display detials button is pushed, how do i get the results of that query to display in the text boxes in my form? I have one text box for each field in my record and the query only returns one record.
 
I'm assuming your using mysql_fetch_array, or the equivalent for another db, in which the different fields of the record will be stored as elements of an array.
(myarray[0], myarry[1] ...myarray[n])
Just give the different array elements as the values of your text boxes, with the first field being element '0'
 
I'm sorry but I don't understand. Maybe if you show me the code for the part that you put in the text box value I would understand better what you are saying. Thanks.
 
I think what Niclov was trying to ask is what type of function are you using to get the values out of your database?

mysql_result(), mysql_fetch_array(), mysql_fetch_object() or something similar.

You can then loop through the array or class like so:

[tt]

$sql = "SELECT * FROM table WHERE id=1";
$result = mysql_db_query("database",$sql) or die("failed query");
$result_array = mysql_fetch_array($result);

for ($i=0; $i<count($result_array); $i++) {
print &quot;<input type=\&quot;text\&quot; name=\'&quot;.$result_array[$i].&quot; value=\&quot;&quot;.$result_array[$i].&quot;\&quot;><br>&quot;;
}
[/tt]

I think that is what Niclov was trying to say.

Hope this helps.

-Vic
vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
Sure thing

With MySQL, you'd get your result using
$result= mysql_query([querystring]);
Giving you a resource variable --> $result
Since your query only returns one record, the statement
$myvar= mysql_fetch_array($result);
Will put the different fields of the record into the variable $myvar, which will be created as an array. The different fields of the record will be the elements of the array, so $myvar[0] will have the value of the first field of your records, $myvar[1] will have the second and so forth.

To put these values into a text box, it's just
<input type=&quot;text&quot; name=&quot;field1&quot; value=&quot;<?=$myvar[0]?>&quot;>
in straight HTML
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top