realjumper Posted January 26, 2009 Share Posted January 26, 2009 Hi, I retrieve and echo my searched data via a while loop. The data is for students details. Each row of the generated html table shows the students username, first name, last name, email, campus, status, and a checkbox to delete the account. The 'status' is a drop down to show the current status of each student, like for example, 'Graduated', 'Left', 'Expelled' etc etc. If the status of a student has changed, the new status can be selected from the drop down and the page refreshes with the new status and the DB is updated. This is all good. The delete account checkbox in each html row is to delete the account...obviously. One or more checkboxes can be checked, and upon clicking the 'Delete Account(s) button, the selected accounts are deleted, and the page refreshes and the DB is updated. This is all good too :-) If the user doesn't enter any details into the search text area, then it will retrieve all students, and sometimes this is useful because several students account details may need updating at the same time, so instead of searching student by student, they all appear on the one page. Now, if (say) a student account is either changed status or deleted, the page refreshes and the DB gets updated, and the page obviously loads from the top again. It would be nice to have the page reload in the same position again. I know that an internal html anchor will do this and I'm guessing that I could name each row, for example, row 1, row 2, row 3 etc etc, and then via the 'GET' method I should be able to reload the page in the same position it was before. The question is, can I have something like that done by the same loop I am using to retrieve the data. Here is a cut-down version of my code: while($row2 = mysql_fetch_array( $result2 )) { $first_name = stripslashes($row2[first_name]); $last_name = stripslashes($row2[last_name]); if ($row99[student_staff] == 'staff') { echo "<tr style=\"font-size:12px;text-align:left;\" bgcolor=\"#ffffff\">"; echo "<td><a href=\"edit.php?sid=$row2[sid]\">$row2[sid]</a> </td>"; echo "<td>$first_name </td>"; echo "<td>$last_name </td>"; echo "<td>$row2[email] </td>"; echo "<td>$row2[campus] </td>"; echo "<td align=\"center\">"; echo "<select name=\"menu1\" onChange=\"MM_jumpMenu('parent',this,0)\">"; echo "<option value=\"searchit.php?find=$find&sid=$row2[sid]&update=yes&status=$row2[status]\">$row2[status]</option>"; // Retrieve all the data from the table $result888 = mysql_query("SELECT DISTINCT status FROM status Order BY status") or die(mysql_error()); while($row888 = mysql_fetch_array( $result888 )) { echo "<option value=\"searchit.php?find=$find&sid=$row999[sid]&update=yes&status=$row888[status]\">$row888[status]</option>"; } echo "</select>"; echo "</td>"; Essentially I am asking if it is possible to include (in laymans terms) something like this, and if so, how? If not, what are my choices? I thought of Ajax but I'm not at the level sadly. $num = '1'; while($row2 = mysql_fetch_array( $result2 ) && $num <1000 ) { $num = $num + '1'; echo "<td>$first_name <a name=$num></a></td>" } The above code is obviously a shortened version, but I hope you understand what I'm trying to do!! Quote Link to comment https://forums.phpfreaks.com/topic/142534-solved-increment-number-in-while-loop-question/ Share on other sites More sharing options...
MadTechie Posted January 26, 2009 Share Posted January 26, 2009 Okay i think i know what you are trying to do.. and yes you could add a counter but i would suggest you use the Unique User ID (AutoNumber) so echo "<td>$first_name <a name=\"User{$row2['ID']}\"></a></td>" also you should quote the field names ie $row2[first_name] should be $row2['first_name'] Quote Link to comment https://forums.phpfreaks.com/topic/142534-solved-increment-number-in-while-loop-question/#findComment-746930 Share on other sites More sharing options...
realjumper Posted January 26, 2009 Author Share Posted January 26, 2009 Okay i think i know what you are trying to do.. and yes you could add a counter but i would suggest you use the Unique User ID (AutoNumber) so <snip> Ahh yes of course!! That makes sense...thank you Quote Link to comment https://forums.phpfreaks.com/topic/142534-solved-increment-number-in-while-loop-question/#findComment-746980 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.