Click here to Skip to main content
15,302,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to do a loop to extract every single "sample ID" from the list and execute the code below.

The "Sample IDs" contain all the ID values ​​(ex: GD6871) from 1 to N, where N is the size of the list in terms of the number of "Sample IDs" present.

The ID values ​​are on another page, so it must be able to get these values ​​with ($ _GET ['idList']); , unpack them to be able to read them here.

What I have tried:

PHP
//The given code
$sampleIDList = htmlspecialchars($_GET['idList']);

for i = 1 to N ...   //Part of the click is what I need.

...

 
$sampleID = $sampleIDList(i);




//Instruction of the page from where I have to import the IDs automatically.

<td><?=$test->sampleID?><br>
                                
<?=$reportStatusDisplay?>
</td>
Posted
Updated 7-Dec-21 5:33am
v2
Comments
Chris Copeland 7-Dec-21 8:53am
   
What values are being passed in to $_GET['idList']? Is it a string value delimited by something like commas or new-lines?
iMati 7-Dec-21 9:15am
   
It's an array of strings, actually, an array of values ​​that I've concatenated into on the other page.

1 solution

You mention you've concatenated together the values into the $_GET['idList'] value so what you'll need to do is split the values again back into an array before you can iterate over them.

You can split using the PHP: explode - Manual[^] function, which will take the string value and split it based on a delimiter.

For example, if your string has been concatenated with a comma as the delimiter then you'd need to explode on that:
PHP
$idList = $_GET['idList'];
$idArray = explode(",", $idList);

foreach ($idArray as $id) {
  $id = htmlspecialchars($id);
}
   
Comments
iMati 9-Dec-21 3:48am
   
That's all I needed! Thank you so much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900