Jump to content

[SOLVED] Increment number in while loop question


realjumper

Recommended Posts

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!!

 

Link to comment
Share on other sites

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']

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.