Jump to content


Photo

take results from a mysql query and assign to variables


  • Please log in to reply
1 reply to this topic

#1 gterre

gterre
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 24 August 2006 - 06:56 PM

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.

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 24 August 2006 - 07:06 PM

I think that this is what you want

$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);


Hope this helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users