Jump to content

Archived

This topic is now archived and is closed to further replies.

gub

Looping through array contents

Recommended Posts

Hi,

The code below is an attempt to search alter one database table (which it does fine), then to take all the information in `lists` to search for all the values in there that are in the rows "userid(x)". The script manages to get all of that information out ok and echo's it ok too. All the values that are required are passing through the code ok too.

What the script then is meant to do with this information is to run through each of the `userlist` values for each of the values of "userid(x)" to find $listid and then set that value to '0'. This doesn't do this at all and if it does do anything, it will only iterate through as far as the third value in the "userid(x)" array.

Can anyone see where I am going wrong, as I have been staring at this code for a long time now and am getting quite frustrated with it!

Regards,
Matt Wombell

[code]
if (strcmp($tutorpass,$tutorpasstext) == 0) {
    //get list values (numerical) from form posted
    $listid = $_POST['listname'];
    echo "listid: $listid<br>";
    
    //getdate
    $sqldate = date("Y-m-d H-i-s");
    
    //archive the list
    //change the db values to record it as archived and the date + time archived at
    $doarchive = "UPDATE `lists` SET `archived` = '$sqldate', `active` = 2 WHERE `listid` = '$listid'";
    $doingarchive = mysql_query($doarchive);
    echo "doarchive = $doarchive<br>";
    
    //remove this list from the userlist of each student
    $getusersfromlist = "SELECT * FROM `lists` WHERE `listid` = '$listid'";
    $gotusersfromlist = mysql_query($getusersfromlist);
    $gotusersarray = mysql_fetch_array($gotusersfromlist);
    echo "gotusersfromlist = $getusersfromlist<br>";
    
    $listidinlist = 0;
    while ($listidinlist < 100) {
        $listidfromlist = "userid".$listidinlist;
        echo "listidfromlist: $listidfromlist<br>";        
        $gotusersid = $gotusersarray["$listidfromlist"];
        echo "gotusersid = $gotusersid<br>";
        //when found listid, insert '0'
        if ($gotusersid != 0) {
            //if userid does not equal 0, find list in array
            $listforremoval = 0;
            while ($listforremoval < 500) {
                $findusersfromuserlist = "SELECT * FROM `userlists` WHERE `userid` = '$gotusersid'";
                $findusersfromuserlist = mysql_query($findusersfromuserlist);
                $foundusersarray = mysql_fetch_array($findusersfromuserlist);
                echo "gotusersfromlist = $getusersfromlist<br>";
                    
                //search through the lists
                $tryingtofindthelisttomatchthelistid = "list".$listforremoval;
                echo "$tryingtofindthelisttomatchthelistid<br>";
                $ahagotthelistid = $foundusersarray["$tryingtofindthelisttomatchthelistid"];
                if ($ahagotthelistid == $listid) {
                    $updateuserlists = "UPDATE `userlists` SET `$tryingtofindthelisttomatchthelistid` = '0' WHERE `userid` = '$listidinlist'";
                    $doupdateuserlists = mysql_query($updateuserlists);
                    echo "updateuserlists: $updateuserlists<br>";
                    break;
                }
                $listforremoval = $listforremoval + 1;
            }
        }
        $listidinlist = $listidinlist + 1;

    }
    /*echo "<script type=\"text/javascript\">window.location.href='assigned.php?p=valid&s=".$s."&t=".$t."&u=".$u."&e=yes&ran=".$randcheck."&row=9&error=done';</script>";
    */echo "done 1<br>";
} [/code]

Share this post


Link to post
Share on other sites

×

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.