Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/109689-sort-and-collate-results/
Share on other sites

  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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.