James84 Posted July 8, 2013 Share Posted July 8, 2013 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/279958-setting-the-pointer-of-a-while-do-loop-to-match-the-current-variable/ Share on other sites More sharing options...
requinix Posted July 8, 2013 Share Posted July 8, 2013 You can't have multiple elements on a page with the same ID. It's supposed to be unique. Quote Link to comment https://forums.phpfreaks.com/topic/279958-setting-the-pointer-of-a-while-do-loop-to-match-the-current-variable/#findComment-1439959 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.