Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Update (same page & dynamic) - with Textbox-List-View
Old 12-02-2009, 06:31 PM Update (same page & dynamic) - with Textbox-List-View
Junior Talker

Posts: 3
Name: Jay
Location: Ireland
Trades: 0
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?

edit.php
...
...

Code:
$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... 
   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...

...
edit.php
...

Code:
      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 (not link, and many on page) 
         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.php and the T2 (per T1 id) list in edit.php.

Note: - The edit.php for T2 (images) will always display all rows per the Menu_Id on Update - and not load to an Edit with just that row.
(I would then issue a Row changed message - which is fine!)

Possibly a slightly trickier one, but I'll remain hopeful someone could suggest some refined direction/ suggestions...

Many thanks
(see images: http://www.phpfreaks.com/forums/inde...tml#msg1320785)
pipi219 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-03-2009, 03:13 AM Re: Update (same page & dynamic) - with Textbox-List-View
Super Talker

Posts: 139
Name: John Davis
Trades: 0
You have to append image_id to textbox name
Code:
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[" .$row['image_id']. "]' value='" .stripslashes($row['image_name']) ."'/></td>"; 
echo "<td valign='top'><input type='text' name='image_position[" .$row['image_id']. "]' value='" .stripslashes($row['image_position']) ."'/></td>"; 
echo "<td valign='top'><input type='text' name='image_file[" .$row['image_id']. "]' value='" .stripslashes($row['image_file']) ."'/></td>"; 
echo "<td valign='top'><input type='submit' value='Update Image' /><input type='hidden' value='1' name='submbit_update' />";
Then you'll get the array of values.
__________________
»
Please login or register to view this content. Registration is FREE
- Interactive maps for websites
»
Please login or register to view this content. Registration is FREE
for web developers
MapMaster is offline
Reply With Quote
View Public Profile Visit MapMaster's homepage!
 
Old 12-04-2009, 04:54 AM Re: Update (same page & dynamic) - with Textbox-List-View
Super Talker

Posts: 139
Name: John Davis
Trades: 0
By the way.
You can use something like:
Code:
<input type='text' name='namevalue[]' />
<input type='text' name='namevalue[]' />
<input type='text' name='namevalue[]' />
<input type='text' name='namevalue[]' />
So, you'll get the numeric array $namevalue
__________________
»
Please login or register to view this content. Registration is FREE
- Interactive maps for websites
»
Please login or register to view this content. Registration is FREE
for web developers
MapMaster is offline
Reply With Quote
View Public Profile Visit MapMaster's homepage!
 
Old 12-04-2009, 02:17 PM Re: Update (same page & dynamic) - with Textbox-List-View
Junior Talker

Posts: 3
Name: Jay
Location: Ireland
Trades: 0
Many thanks MapMaster

And will this allow me to edit the data as per the attached images (edit.php) where I have the EDIT ME highlighted (see opening post attachments -> images).
I had since reading about AJAX (javascript) dataGRID, but I don’t want to have to use JS for this functionality, (although I will use js for form validation, when I get this update issue working).

Last edited by pipi219; 12-04-2009 at 03:58 PM..
pipi219 is offline
Reply With Quote
View Public Profile
 
Old 12-05-2009, 05:04 PM Re: Update (same page & dynamic) - with Textbox-List-View
Junior Talker

Posts: 3
Name: Jay
Location: Ireland
Trades: 0
Update: Resolved with:

Code:
<td valign='top'>".nl2br($row['image_id'])."</td>
<input type='hidden' name='image_id' value='".$row['image_id']."'>
and now on to redirects and validation...
pipi219 is offline
Reply With Quote
View Public Profile
 
Old 01-15-2010, 03:16 PM Re: Update (same page & dynamic) - with Textbox-List-View
Junior Talker

Posts: 1
Name: Shane
Trades: 0
My correct and updated code
PHP Code:
processForm();
getHTML();

function 
getHTML() {
    
$formHTML '<STYLE>
  tr { background-color: #DDDDDD}
  .initial { background-color: #DDDDDD; color:#000000 }
  .normal { background-color: #CCCCCC }
  .highlight { background-color: #CCCCFF }
</style>'
;
    
$formHTML .= "<form method=\"post\" action=\"{$PHP_SELF}\">";

    
// Create a checkbox for each plugin, if the show_no_msg field is set to 1, check the box (that's the ternary operator)
    
$qry DB_query("SELECT * FROM gl_plugins");
        
$formHTML .= '<table><tr><th>Plugin</th><th>Include in WNB</th><th>Show No Message</th><th>Order</th></tr>';
    while(
$row DB_fetchArray($qry)) {
        
$formHTML .= '<tr onMouseOver="this.className=\'highlight\'" onMouseOut="this.className=\'initial\'" >';
        
$formHTML .= '<td>' $row['pi_name'] . '</td>';
        
$formHTML .= '<td align=center> <input type="checkbox" name="gf_incl[]" value="' $row['pi_name'] . '" ' . ($row['include_in_WNB'] == ?  'checked' '') . '></td>';
        
$formHTML .= '<td align=center> <input type="checkbox" name="gf_msg[]" value="' $row['pi_name'] . '" ' . ($row['show_no_msg'] == ?  'checked' '') . '> </td>';
        
$formHTML .= '<td align=center> <input type="text" name="gf_order[]" size= "2" > </td>';
        
$formHTML .= '</tr>';
    }
    
$formHTML .= '<tr><td><input type="submit" name="gl_plugins_submit" value="Submit"></td><td></td><td></td><td></td></tr>';  
    
$formHTML .= '</form>';
        
$formHTML .= '</table>';
    echo 
$formHTML;
}


function 
processForm() {
    if(
$_POST['gl_plugins_submit']) {
        
$gfmsg = ($_POST['gf_msg'] ? $_POST['gf_msg'] : array());
        
$gfincl = ($_POST['gf_incl'] ? $_POST['gf_incl'] : array());
        
$gforder = ($_POST['gf_order'] ? $_POST['gf_order'] : array());
        
// for each of the plugins in the database
        
$qry DB_query("SELECT * FROM gl_plugins");
        while(
$row DB_fetchArray($qry)) {
            
// if the plugin is checked, set its order value in the database to 1, else set it to 0
            
if(in_array($row['pi_name'], $gfincl))   {
                
DB_query("UPDATE gl_plugins SET include_in_WNB = '1' WHERE pi_name = '{$row['pi_name']}'");
            } else {
                
DB_query("UPDATE gl_plugins SET include_in_WNB = '0' WHERE pi_name = '{$row['pi_name']}'");
            }
            
// if the plugin is checked, set its show_no_msg value in the database to 1, else set it to 0
            
if(in_array($row['pi_name'], $gfmsg))   {
                
DB_query("UPDATE gl_plugins SET show_no_msg = '1' WHERE pi_name = '{$row['pi_name']}'");
            } else {
                
DB_query("UPDATE gl_plugins SET show_no_msg = '0' WHERE pi_name = '{$row['pi_name']}'");
            }
            \\ if(
in_array($row['order'], $gforder) && in_array($row['pi_name'], $gforder))   {
                
DB_query("UPDATE gl_plugins SET `order` = '{$gforder['order']}' WHERE pi_name = '{$row['pi_name']}'");
            \\ } 
        }

    }



Last edited by ofey; 01-15-2010 at 03:52 PM..
ofey is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Update (same page & dynamic) - with Textbox-List-View
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.05606 seconds with 12 queries