Jump to content

TomOlsson

Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by TomOlsson

  1. My god. I must've looked over my code a thousand times without noticing this error. Thank you.
  2. Hello, I'm having a slight issue, which I'm not sure why I'm having. I'm basically retrieveing an array of objects from a database, and first modifying a parameter of each object using a for-each loop, then sorting them using a for-loop based on the modified parameter before publishing them. Or well, that is the plan except I can't access the objects properly during the for-loop. The code which is not working is this: for($i=0; $i<($len); $i++){ echo 'Innan if </br>'; echo 'Result['.$i.']='.$result[i]->hits.'</br>Result['.($i+1).']='.$result[i+1]->hits.'</br>'; //First ->hits value is always 1, seconds is null. if (($result[i]->hits) < ($result[i+1]->hits)){ echo 'efter IF'; //Reached only once. Original array has lowest-highest (roughly) so this should fire dozens of times $dummy = $result[i]->hits; $result[i]->hits = $result[i+1]->hits; $result[i+1]->hits=$dummy; $bool = true; echo $result[i]->hits.'</br>'; }} Well, it sort of works. It loops and goes around, the if is true once. But it's not drawing it's values from the objects inside the array. As I've commented inside the code, it's not throwing errors, but it's not doing what it should do either. I'm assuming that this has to do with my array containing objects, so I need add another step in here to get the object on each location in the array... Maybe. Any ideas? Using a foreach solves the value issue, but it's obviously sketchy to use it during a bubblesort. Can post full code if relevant, though this is the only part which is not working the way I expect it to. The output is this: Result[0]=Result[1]=1efter IF1Innan ifResult[1]=1Result[2]=Innan ifResult[2]=1Result[3]=Innan ifResult[3]=1Result[4]=Innan ifResult[4]=1Result[5]=Innan ifResult[5]=1Result[6]=Innan ifResult[6]=1Result[7]=Innan ifResult[7]=1Result[8]=Innan ifResult[8]=1Result[9]=Innan ifResult[9]=1Result[10]=Innan ifResult[10]=1Result[11]=Innan forInnan ifResult[0]=1Result[1]=Innan ifResult[1]=1Result[2]=Innan ifResult[2]=1Result[3]=Innan ifResult[3]=1Result[4]=Innan ifResult[4]=1Result[5]=Innan ifResult[5]=1Result[6]=Innan ifResult[6]=1Result[7]=Innan ifResult[7]=1Result[8]=Innan ifResult[8]=1Result[9]=Innan ifResult[9]=1Result[10]=Innan ifResult[10]=1Result[11]=
×
×
  • Create New...