ThunderAI Posted June 11, 2008 Share Posted June 11, 2008 I am currently working on some code that sorts through a list of things and compares it to a list of other things in three different lists. The sort structure is for each of the different lists > for each item in list a to compare to list x > > While there are matches as govered by the SQL Statement, display the problem is this leads to having the same record in list x repeated multiple times, and i would like to avoid that. I have tried this code: while ($newarray = mysqli_fetch_array($objrs_support, MYSQLI_ASSOC)) { for($j=0; $j<sizeof($known_sids); $j++) { echo $j; if ($known_sids[$j] == $newarray['ruat_tsa_sid'] ) { echo "looping j ".$j; // We already added this guy to the list, do not add again echo "Repeat Customer, Do not add them again<br>"; } else { echo "new j ".$j; $known_sids[$j] = $newarray['ruat_tsa_sid']; When i try this i get an error "Cannot use a scalar value as an array in " which i am sure it is because i am attempting to do a for loop in an array that keeps changing size. How do i block a repeat ID from being displayed across the x number of lists? The intent here was to have $known_sids keep a list of known IDs across all of the different lists and compare a new result to those in the list, if the new ID matched one in the array then dont display it. Help, please Quote Link to comment https://forums.phpfreaks.com/topic/109689-sort-and-collate-results/ Share on other sites More sharing options...
tapos Posted June 11, 2008 Share Posted June 11, 2008 U can have an array which will contains displayed list. When u wan to display any id, check that array first or u can pull the distinct data from the database. hope this will help u. Quote Link to comment https://forums.phpfreaks.com/topic/109689-sort-and-collate-results/#findComment-562858 Share on other sites More sharing options...
ThunderAI Posted June 11, 2008 Author Share Posted June 11, 2008 Quote U can have an array which will contains displayed list. When u wan to display any id, check that array first or u can pull the distinct data from the database. hope this will help u. What i tried last night was to store all of the IDs in an array and then remove the duplicates from the array, then you have to reopen a connection to the database to loop through the array. That adds time to the process and is not ideal. I do not see how i can check to see if the ID is already in the array, and if it is not to display the row in one step. what i want is a way to prevent a row that already has been shown from being displayed again. Quote Link to comment https://forums.phpfreaks.com/topic/109689-sort-and-collate-results/#findComment-563137 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.