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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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