Jump to content

take results from a mysql query and assign to variables


gterre

Recommended Posts

Hello,

I am stuck on this one problem which I bet is really simple. I am trying to create an edit form which shows the current data in each respective fields. I know its down by assigning the value="" attribute of the form field. however i need to query the database for the record in question and assign the results of the query into variables so i can insert into the value attribute. Can someone give me an example of pulling a query and setting the results for each field into a variable?

Thank you this help is much appreciated.
I think that this is what you want

[code=php:0]
$sql = mysql_query("SELECT * From `sometable` WHERE `something` = '$something'")or die(mysql_error());
while ($rw = mysql_fetch_assoc($sql)) {
    echo '<input type="text" name="' . $rw['some_field'] . '" value="' . $rw['somefield'] . '">
            <input type="text" name="' . $rw['some_field2'] . '" value="' . $rw['somefield2'] . '">';
}
mysql_free_result($sql);
[/code]


Hope this helps,
Tom

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.