Jump to content

Setting the pointer of a while do loop to match the current variable


James84

Recommended Posts

I'm having a bit of trouble maintaining the value of a variable within a while do loop.  It seems the pointer keeps pointing to the first id no matter how many loops there are.  I've inserted a hidden field which pulls in each id with shows the IDs are fine but whenever I click on 'editForm' anchor it always points to either the first or last id in the loop, (depending on whether I put the editForm div tag before or after the loop).  Can anyone out there help me fix this problem?  The code is shown below:
 

$('.formEditAnchor').click(function() {
    $('#editMyForm').submit();
});
 
<?php
 function editFunction($editID) {
 
  $database = new database();
 
  $res = $database->selectDB("select content as EditContent from content where id = '$editID'");
 
  $editForm = "<form method='POST' action='_scripts/_php/edit-file.php'>";
  $editForm.= "<textarea name='saveContent' cols='70' rows='25'>";
  
 while($row = mysql_fetch_array($res)) {
  $row = mysql_fetch_array($res);
    $editableFile = $row['EditContent'];
    $editableContent = file($editableFile);
    $editableString = implode($editableContent);
   
 }
   
  $editForm.=  $editableString;
                   
  $editForm.= "</textarea>";
  $editForm.=  "<input type='hidden' name='hiddenEditPath' value='<?php echo $editableFile; ?>' />";
  $editForm.=  "<br />";
  $editForm.=  "<input type='submit' name='saveFile' value='Save'>"; 
  $editForm.=  "</form>";
  
  return $editForm;
 }
 
 function submitEditForm() {
  
  if (isset($_POST['formEditAnchor'])) {
  
   $usersReplyId = $_POST['hiddenUserReplyID'];
   $returnEdit = editFunction($usersReplyId);
   
   return $returnEdit;
   
  }
 }
 $result3 = $database->selectDB("select * from blog_content where content_id = '$id'");

 $r = array(); 
 while($rows = mysql_fetch_array($result3)) {
 
  $myID = $rows['id'];
  $file = $rows['content'];
  $contents = file($file);
  $string = implode($contents);
  
?>
    <form name="editMyForm" id="editMyForm" method="post" action"<?php echo $_SERVER["PHP_SELF"]?>">
    <input type="hidden" name="hiddenUserReplyID" id="hiddenUserReplyID" value="<?php echo $myID ?>" />
    <table>
    <tr>
     <tr>
      <td bgcolor="#F8F7F1" align="center">Date/Time:<?php echo $rows['datetime']; ?></td>
     </tr>
     <tr>
      <td bgcolor="#f8f7f1"><?php
      
                echo $string;
                echo "<br /><br />";
           
            ?>
      </td>
     </tr>
     <tr>
      <td><a href="#editContent" class="create-content" id="formEditAnchor" onclick="<?php $myReturnEdit = submitEditForm(); ?>">Edit File</a></td>
     </tr>
    </tr>
    </table>
   </form>
    
<?php
}
?>
<div id='editContent' class='create-topic'>
    <?php
     echo $myReturnEdit;
?>
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.