Jump to content

Update (same page & dynamic) - Textbox-List-View with individual row Edit/Update


momo219

Recommended Posts

So... I have a 2 Table (mysql) Db. Table 1 = (sub)Menu, Table 2 = Images per (sub)Menu.

 

Typical scenario - new.php - loads a form with a MENU ADD form, and a List of current Menus (with Edit and Delete).

 

Edit loads Edit.php, with MENU Edit form (id got from new.php) which lists items per menu_id (T2, images). The row values, (not id's/ pks) are output in TEXT boxes

 

- and My question is how can I make these editable text-box, EDITABLE in their list view, so I can Update on the same page?

...
$result = mysql_query("SELECT * FROM `images` WHERE `imageMenu_id` = '$id' ORDER BY image_position ASC") or trigger_error(mysql_error());
  while($row = mysql_fetch_array($result)){
    foreach($row AS $key => $value) {
      $row[$key] = stripslashes($value);
  }

  // While - - Do this once for each... ie create row and populate per $id (above)...
    echo "<form name ='add_update' action='' method='POST'>";
    echo "<tr>";
      echo "<td valign='top'>" . nl2br( $row['image_id']) . "</td>";
      echo "<td valign='top'>" . nl2br( $row['imageMenu_id']) . "</td>";
      echo "<td valign='top'><input type='text' name='image_name' value='" .stripslashes($row['image_name']) ."'/></td>";
      echo "<td valign='top'><input type='text' name='image_position' value='" .stripslashes($row['image_position']) ."'/></td>";
      echo "<td valign='top'><input type='text' name='image_file' value='" .stripslashes($row['image_file']) ."'/></td>";
      echo "<td valign='top'><input type='submit' value='Update Image' /><input type='hidden' value='1' name='submbit_update' />";
    echo "</tr>";
  echo "</form>";
}
echo "</table>";

I had been trying along the lines of this, but I cant grab the individual row id...

 

if (isset($_POST['submbit_update'])) {
  $sql = "UPDATE `images` SET `image_name`= '{$_POST['image_name']}', `image_position`= '{$_POST['image_position']}', `image_file`= '{$_POST['image_file']}'
  WHERE `image_id` = '$????????'"; // $IMAGEid - cant grab this per UPDATE BUTTON
  mysql_query($sql) or die(mysql_error());
  echo (mysql_affected_rows()) ? "Edited row. " : "Nothing changed. ";
}

 

Key to this is not requiring another page, as I have the T1 list on new and the T2 (per T1 id) list in edit.php

 

Hopefully someone could suggest some refined direction/ suggestions...

 

Many thanks

 

[attachment deleted by admin]

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.