Jump to content

gub

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

gub's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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]
  2. [!--quoteo(post=365533:date=Apr 17 2006, 03:54 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 17 2006, 03:54 PM) [snapback]365533[/snapback][/div][div class=\'quotemain\'][!--quotec--] What errors are returned? [/quote] Right, When inserting the values of [code]$listid = 9[/code] & [code]$boxid = 3[/code], (which gets array values of 1,3,4 and 5 at [code]$findusersonlistarray = mysql_fetch_array($findusersonlistsql);[/code] the code as it stands runs and inserts the values for $fuol = 1 and $fuol = 3, then returns to $fuol = 1 again and then keeps looping until I intervene and press stop in the browser. That help?
  3. Hi, I've been trawling through this script for a fair few hours now trying to find the error. I've made code hacks and all sorts to it, but have not had any luck yet. If someone can find the problem with it, that would be much appreciated! I have commented the code as best I can - if you need clarification - just let me know and I'll try to provide it. Many thanks to those who have a look. Regards, Matt Wombell [code] <?php $link = mysql_connect('localhost', 'xxx', 'xxx')    or die('Could not connect: ' . mysql_error()); echo 'Connected successfully'; mysql_select_db('xxx') or die('Could not select database'); //IGNORE UNTIL FURTHER NOTICE.... note: values for $u, $s, $t, $p, $e, $randcheck, $row are all taken from the db in the missing code below . . . - code removed - site security check! . . //users table query $usertable = "SELECT * FROM `users` WHERE userid='$u'"; $getuser = mysql_query($usertable); $gotuser = mysql_fetch_array($getuser); $user = $gotuser['fname']; //schools table query $schoolstable = "SELECT * FROM `schools` WHERE schid='$s'"; $getsch = mysql_query($schoolstable); $gotsch = mysql_fetch_array($getsch); $sch = $gotsch['school']; $continue = 0; //check the tutor password $tutorpass = $_POST['tutorpass']; $checktutorpass = "SELECT * FROM `users` WHERE userid='$u'"; $tutorpasssql = mysql_query($checktutorpass); $tutorpassfetch = mysql_fetch_array($tutorpasssql); $tutorpasstext = $tutorpassfetch['password']; if (strcmp($tutorpass,$tutorpasstext) == 0) {     $continue = 1; } else {     echo "wrong password"; } //if tutor password is ok, then continue... while ($continue == 1) {     //get box and list values (numerical) from form posted     $boxid = $_POST['boxname'];     $listid = $_POST['listname'];     echo "listid: $listid<br>";     echo "boxid: $boxid<br>";          //add the listid to the box sql table     $grabboxsql = "SELECT * FROM `boxinfo` WHERE `boxno` = $boxid";     $doboxsql = mysql_query($grabboxsql);     $gotboxsql = mysql_fetch_array($doboxsql);          //find list number to assign as (iterate until an empty '$slid' value is found)     $sl = 1;     while ($sl <= 10){         $slid = "sl".$sl;         $whatsl = $gotboxsql["$slid"];         if ($whatsl == 0) {             //update the sl(X) value             $updatelist = "UPDATE `boxinfo` SET `$slid` = '$listid' WHERE `boxno` = '$boxid'";             $doupdatelist = mysql_query($updatelist);             $doneanupdate = 1;             break 2; //break out of the two while statements         }         else {             $sl = $sl + 1; //otherwise iterate until an empty '$slid' is found         }     } } //continues if an update has been done to the '$slid'... while ($doneanupdate == 1) {         //find users on the list that has been added to sl(X)     $findusersonlist = "SELECT * FROM `lists` WHERE `listid` = '$listid'";     $findusersonlistsql = mysql_query($findusersonlist);     $findusersonlistarray = mysql_fetch_array($findusersonlistsql);          //find the users in the list (in array order e.g. 1,3,4,5)     $fuol = 1;     while ($fuol <= 100) {         $fuoluser = "userid".$fuol;         $fuolvalue = $findusersonlistarray["$fuoluser"];         //finds when a userid is not 0         while ($fuolvalue > 0) {             //find first available row with '0' in it             $space = 0;             while ($space < 500) {                 $findingspace = "SELECT * FROM `userlists` WHERE `userid` = '$fuol'";                 $findingspacesql = mysql_query($findingspace);                 $findingspacearray = mysql_fetch_array($findingspacesql);                                                  $spacevalueid = "box".$space;                 $spacevalue = $findingspacearray["$spacevalueid"];                 if ($spacevalue == 0) {                     //if empty one is found, update the list value in the `userlists` table                     $updatespace = mysql_query("UPDATE `userlists` SET `$spacevalueid` = '$boxid' WHERE `userid` = '$fuol'");                     //set the update pointer                     $doneanotherupdate = 1;                     //echo to say completed and what action done                     echo "done an insert at $spacevalueid = $boxid where userid = $fuol<br>";                     break 2; //break out of the two while statements                 }                 else {                     $space = $space + 1; //otherwise iterate                 }             }                      }         $fuol = $fuol + 1; //iterate $fuol to get new $fuol value to continue thru the array values     } } //echo statements to show that the script has completed echo "i think i've inserted the sl value - but please check `boxinfo`!<br>"; echo "done insert of values to users - check - i may be lying!"; /* the issues:     will work up to the point where it searches through values that are not in the array and ends up in a loop */ ?>[/code]
×
×
  • 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.