Forum Moderators: coopster

Message Too Old, No Replies

nesting 2 mysql_fetch_field and mysql_fetch_row?

to auto-generate maintenance forms for db

         

jamie

8:05 pm on Apr 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



would like to create a one-size-fits-all set of forms for ease of mysql db maintenance.

so far i have an add_data.php which autogenerates the fields according to the # and type of fields:

if ($fields) {
while($field=mysql_fetch_field($fields)) {
// fetch all the field types and display input text or textarea accordingly for each field
if (($field->type!="timestamp") &&
(strPos(mysql_field_flags($fields,$i),"auto_increment") == false))
{
$rows = "<tr>\n";
$rows .= "<td>$field->name</td>\n";
if ($field->numeric == true){
$rows .= "<td><input type=text id=$field->name name=$field->name></td>\n";
}
// then test for string and blob
... }
}

i would like to use a similar function to edit the db, by autogenerating the form using the mysql_fetch_field function but incorporating the values based on the ID variable passed in the url by using mysql_fetch_row

the end result would be edit_data.php which could be used as a generic form for updating all types of table.

obviously i need to get the ID

$ID=$_POST['id'];
// then get all the info out of database
while ($get_info = mysql_fetch_row($result)) {
// then i read out all the values
foreach ($get_info as $value) {
// then i can insert $value in each form tag..

e.g.

$rows = "<tr>\n";
$rows .= "<td>$field->name</td>\n";
if ($field->numeric == true){
$rows .= "<td><input type=text name=$field->name value=$value></td>\n";

i am just not sure how to insert the $value

many thanks!

jatar_k

5:08 am on Apr 30, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hmm, not totally sure what you mean by not knowing how to insert the $value. Doesn't the foreach loop work? Are you getting an error? or nothing?