SchweppesAle Posted April 6, 2009 Share Posted April 6, 2009 hi, I'm having trouble cycling this list of users. there are four columns; AuthorID, AuthorName, position, stage. It's intended to pull the last authorName and ID based on position then slip it into the first position and move the rest down. Instead it pulls the second to last and places it at the top. What makes it strange is the following output which displays both the array containing current list of names/ids vs the updated one which appears to be correct. I think the problem might be in how I'm updating these values to the database, I could be wrong though //output before Jeremy Gooding72Hugh Duffy73Brian Hamilton81Amy Vetter74Scott Koegler75Randolph P. Johnston78Brent F. Goodfellow, CPA.CITP79John Tripi62Greg LaFollette64Nonprofit Technology News67Kurt Martin6563John Higgins76Kathy Yakal68Steven Ladd69Barry MacQuarrie70Geni Whitehouse82 //output after Geni Whitehouse82Jeremy Gooding72Hugh Duffy73Brian Hamilton81Amy Vetter74Scott Koegler75Randolph P. Johnston78Brent F. Goodfellow, CPA.CITP79John Tripi62Greg LaFollette64Nonprofit Technology News67Kurt Martin6563John Higgins76Kathy Yakal68Steven Ladd69Barry MacQuarrie70 After execution it will instead place Steven in the front though; here's a look at the admittedly sloppy code though. <?php $loop = 1; while ($loop == 1) { global $mainframe; $db =&JFactory::getDBO(); $query = "SELECT * FROM #__AuthorList WHERE stage = '0' ORDER BY position"; $db->setQuery( $query, 0, $count ); $rows = $db->loadObjectList(); $counter = 0; /*grabs all primary authors and stores within array*/ foreach($rows as $row) { $primary[$counter][0] = $row ->AuthorName; /*echo $primary[$counter][0];*/ $primary[$counter][1] = $row ->AuthorID; /*echo $primary[$counter][1];*/ $counter++; } echo "<hr/>"; $query = "SELECT * FROM #__AuthorList WHERE stage = '-1' ORDER BY position"; $db->setQuery( $query, 0, $count ); $rows = $db->loadObjectList(); $counter2 = 0; /*grabs all secondary authors and stores within array*/ foreach($rows as $row) { $secondary[$counter2][0] = $row ->AuthorName; /*echo $secondary[$counter2][0];*/ $secondary[$counter2][1] = $row ->AuthorID; /*echo $secondary[$counter2][1];*/ $counter2++; } echo "<hr/>"; $secondarytemp[0][0] = $secondary[$counter2 - 1][0]; $secondarytemp[0][1] = $secondary[$counter2 - 1][1]; for ($x = 0; $x < $counter2; $x++) { $y = $x + 1; $secondarytemp[$y][0] = $secondary[$x][0]; echo $secondarytemp[$y][0]; $secondarytemp[$y][1] = $secondary[$x][1]; echo $secondarytemp[$y][1]; } echo "<hr/>"; /*now to update the actual database*/ global $mainframe; $db =&JFactory::getDBO(); $query = "SELECT * FROM #__AuthorList"; $db->setQuery( $query, 0, $count ); $rows = $db->loadObjectList(); for ($x = 0; $x < $counter2; $x++) { $OriginalName = $secondary[$x][0]; $OriginalID = $secondary[$x][1]; $NewName = $secondarytemp[$x][0]; $NewID = $secondarytemp[$x][1]; echo $NewName; echo $NewID; mysql_query("UPDATE jos_AuthorList SET AuthorName='temp' WHERE AuthorName='$OriginalName'") or die(mysql_error()); mysql_query("UPDATE jos_AuthorList SET AuthorName='temp2' WHERE AuthorName='$NewName'") or die(mysql_error()); mysql_query("UPDATE jos_AuthorList SET AuthorName='$NewName' WHERE AuthorName='temp'") or die(mysql_error()); mysql_query("UPDATE jos_AuthorList SET AuthorName='$OriginalName' WHERE AuthorName='temp2'") or die(mysql_error()); mysql_query("UPDATE jos_AuthorList SET AuthorID='99999' WHERE AuthorID='$OriginalID'") or die(mysql_error()); mysql_query("UPDATE jos_AuthorList SET AuthorID='98989' WHERE AuthorID='$NewID'") or die(mysql_error()); mysql_query("UPDATE jos_AuthorList SET AuthorID='$NewID' WHERE AuthorID='99999'") or die(mysql_error()); mysql_query("UPDATE jos_AuthorList SET AuthorID='$OriginalID' WHERE AuthorID='98989'") or die(mysql_error()); } $loop++; } ?> Link to comment https://forums.phpfreaks.com/topic/152837-not-so-graceful-code-cycles-mysql-list-incorrectly/ Share on other sites More sharing options...
SchweppesAle Posted April 6, 2009 Author Share Posted April 6, 2009 i really don't see why this wouldn't work. Is it the mysql_query? :-\ Link to comment https://forums.phpfreaks.com/topic/152837-not-so-graceful-code-cycles-mysql-list-incorrectly/#findComment-802715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.