Most voted "foreach" questions
Provides an easy way to iterate over vectors and matrices.
Learn more…324 questions
Sort by count of
-
1
votes1
answer55
viewsReceive array values
How I receive the values of this checkbox? <input type="checkbox" name="Item[<?php echo $IDCatalogo; ?>][<?php echo $IDItem; ?>]"> foreach( $_POST['Item'] as $key => $n ) {…
-
1
votes0
answers108
viewsProblems generating JSON with JAVA
I’m having trouble generating this json { "receita": [{ "specialtys": [{ "date": "27/01/2016 00:00:00", "itemSpecialtys": [{ "specialtyId": 1, "specialtyName": "Tabelionato de Notas", "receitas": [{…
-
1
votes2
answers860
viewsArray of unique values with foreach
I got the following foreach to pick up the id of the devices that were used in each sector: @foreach($relatorio->Empresa->SetorEmpresa as $setor) {{ $collection[] =…
-
1
votes1
answer529
viewsInvalid argument supplied for foreach() Using JSON
I’m trying to traverse the foreach with a populated JSON array. To make it easier I’m testing via $_GET (but I’ve tried it with an array populated by php but it didn’t work). The $_GET is like this:…
-
1
votes1
answer573
viewsSubcategory listing according to selected category
I have the following code snippet: <?php foreach($categorias as $cat){ $id_cat = $cat['id']; $subcategorias = array(); $sqlsub = Comando::Executar("SELECT * FROM subcategoria WHERE cat_pai =…
-
1
votes1
answer360
viewsYou can use a foreach of a query within a function
I have a query simple: $Consulta = $pdo->query(" SELECT * FROM dados ")->fetchAll(); foreach ($Consulta as $key) { echo $key["InfoDado"]; } If you execute the foreach of it out of a function!…
-
1
votes0
answers232
viewsReceive all data from a table with only one query
I am trying to create a system that uses Lastfm images. But I want to show only the images of the artists registered in the database. I did so: I made a bank query on condition that banda_id was not…
-
1
votes3
answers12476
views -
1
votes1
answer8366
views -
1
votes1
answer959
views -
1
votes0
answers67
viewsForeach inside if Cakephp
I have an A table that stores an item, and in this table, I have a related B that may have several items aggregated to an item in table A. Follow the if code: if…
-
1
votes2
answers1361
viewsDisplay only one record with foreach
I need help to display only one database record, follow code: <?php $posts = DBRead( 'posts', "WHERE categoria = 3 AND status = 1 ORDER BY data_numero ASC" ); if( !$posts ) echo…
-
1
votes2
answers865
viewsHow to use data from an Array without foreach
I have a function in my Model: public function get_learning_category_list() { $categorias = $this->db->select('t1.id, t1.title, t1.metadata, t1.meta_title, t1.description, t1.meta_description,…
-
1
votes1
answer200
viewsforeach shows 1 wait file then clears and shows another php
I have a foreach in PHP and it shows various data of a XML, but in this XML has 5 photos and I would like the loop to show the first photo, wait about 10 seconds and then show the second photo so…
-
1
votes1
answer318
viewsUsing Else inside the foreach
Guys I have the following code: <?php $string = $_POST['search']; foreach($results['results']['collection1'] as $collection) { if(stristr($collection['prod']['text'],$string) !== false) { echo…
-
1
votes0
answers97
viewsPHP/Bootstrap - Replay up to X and then up to Y then includes new DIV and continues replay
I’m breaking my head in this repetition, as this is my first question, sorry for the mistakes. :) Currently I have this block of codes inside the container: <?php echo '<div class="row">';…
-
1
votes1
answer76
viewsError using Sqlcommand and foreach
I’m trying to go through a list of objects and persist your data in Sqlserver: foreach (var item in pedidos) { cmd.CommandText = "INSERT INTO MinhaTabela (Coluna_A, Coluna_B, Coluna_C) " + "VALUES…
-
1
votes1
answer194
viewsInterim records in foreach
I’m making a list of records and I’m having the following difficulty: In my system I have two tables and I need to list their records interchangeably. The location of the listing is the same. Only I…
-
1
votes2
answers512
views -
1
votes2
answers332
viewsRead string json in php
I need to read the file below: string '{"object":"list","hasMore":true,"limit":10,"offset":0,"data":[{"city":{"object":"city","id":15873,"ibgeCode":"3550308","name":"São…
-
1
votes1
answer799
viewsRead data in an SQL with columns of equal names in different tables
I need to recover data from 2 tables. My SQL presented below works perfectly. The problem is that I made a foreach to recover data from the second table by field ID that is conflicting with the…
-
1
votes1
answer63
viewsI cannot print an array with foreach
I cannot print my array when I put a different key, it gives the error Warning: Invalid argument supplied for foreach(), how to proceed? for ($i=0; $i < 2; $i++) { $use[$i]['outrachave'] = 'some…
-
1
votes1
answer180
viewsHow to complement these queries to get the buyer’s data in the bank?
I made these queries below to get the data from the buyer’s database and the products he bought. With the first query, I got the ID and with these IDS I made a new foreach that took the products…
-
1
votes1
answer48
viewsCreate columns with knockoutJS foreach
Good afternoon, I wanted to 'break' a list of items in 3 columns of 4 items in a knockoutJS foreach. That is, at this point the list is filled down and I would like it to be started via jQuery or…
-
1
votes1
answer40
viewsforeach with error
Someone can give me a hand here, I made this train to take the weekdays, until all right, plus the foreach($periodo as $item) don’t list the last day, someone can tell me what I’m doing wrong! $ini…
-
1
votes2
answers1094
viewsTypeerror: Cannot read Property 'Concat' of Undefined - Typescript?
if (dataFindCategories && dataFindCategories.length !== 0) { let dataFindProducts: Product[]; dataFindCategories.forEach((category) => {…
-
1
votes0
answers25
viewsStop PHP foreach loop after start
How to interrupt a foreach PHP based on a condition coming from the database after starting the loop? $smtm = Connect::getInstance()->query("SELECT * FROM table WHERE num IS NULL"); foreach…
-
1
votes3
answers140
viewsHow do I place a conditional within a . foreach() in Javascript?
I’m making a Scrapping on a website that organizes items with a tag <a>, however I am getting several values with null. How can I place a parole to avoid these values null on the return? const…
-
1
votes1
answer2049
viewsForeach in Select and List
I recently discovered that there’s a big difference between doing some operations, like Select and Where, in Queryable and listed objects such as Enumerable and List. In this and in this question.…
-
1
votes1
answer106
viewsLaravel - Doubt about @foreach?
I have the following code: @foreach($listaProdutos as $key => $listaProduto) @if(...) ... @endif @endforeach Is there any command or way to jump to the next record of $listaProduto if the…
-
1
votes1
answer177
viewsforeach with multiple variables
I’m trying a foreach with several variables like? $record = array(); foreach($resultCustomers as $group) { $record[$group['CODIGO_CLIENTE'].$group['RAZAOSOCIAL']][] = $group['NOME']; } $output =…
-
1
votes1
answer569
viewsInsert array foreach
am tend a problem when entering data in the database with php , I have a form with several checkbox , then I want to select more than 1 checkbox and insert in the database , I did so form <input…
-
1
votes1
answer535
viewsCapture results using Htmlagilitypack
I’m using this code to get results using the Html Agility Pack. This is how it is: WebRequest request = WebRequest.Create(texto); WebResponse response = request.GetResponse(); StreamReader reader =…
-
1
votes1
answer336
viewsHow to encode json with multiple objects in PHP
I need the following result: { "sala": [{ "horario": "18:30", "data": "Seg e Terça" }, { "horario": "10:30", "data": "Quarta Terça" }] } UPDATE I’m doing it like this in PHP: /*criando objeto…
-
1
votes1
answer244
viewsForeach without repeating the name
I have a Foreach in View, and it contains Description, Qtd and dta,how do I make a foreach without repeating the description? Ex: I have a product X whose were removed 10 units day 01/10/2016, 3…
-
1
votes0
answers93
viewsHow to add a comma to each loop string by omitting only the last string?
I have a loop that is generating several names, but need the result of this loop is merged into only one string and names are separated by commas, but omitting the comma in the last name. Expected…
-
1
votes1
answer147
viewsError foreach codeigniter
I’m in the following problem, I make one select in the database and display the images on the page, is a classified portal where the person makes an ad and can upload up to 10 images. So far so…
-
1
votes1
answer183
viewsTwo php foreachs - Duplicate data
I have two selects that return me two arrays and I need to go through them, in the same table, but the records are being duplicated. How can I best resolve this issue ? Follow the example: <?php…
-
1
votes1
answer324
viewsDuplicate items in Foreach
I have two Inputs (curso[] and formacao[]) html and when loop with the foreach and starts to duplicate the items that are within the second foreach This is my class class Pessoa { private $Formacao;…
-
1
votes1
answer149
viewsPHP for each with an if rule
I have a table that brings paid and unpaid commission results. I want him to bring only the pay, I mean, if number_format($row->amount_paid,2) = 0 not bring that line. <?php $i=-1;…
-
1
votes1
answer50
viewsForearch loop how to use with controler
I’m 6 PictureEdit in a PanelControl, and I need to make a run at all the PictureEdit then I made the following code: foreach (PictureEdit Pic in panel1.Controls) { //habilita o meno de zoom…
-
1
votes1
answer548
viewsForeach with this type of JSON (PHP)
I am trying to display the values of a JSON with PHP more unsuccessfully. Code Used: JSON: { "event_name": "offline_message", "widget_id": "sEcXk3TXEw", "visitor": { "name": "ARTULITO BARBOSA DE…
-
1
votes1
answer161
views -
1
votes0
answers76
viewssimplexml_load_file does not return any record
I have the following routine for reading XML file: $arquivo_geral = "xml_categ_1.xml"; if (file_exists($arquivo_geral)) { $xml = simplexml_load_file($arquivo_geral); foreach($xml->categoria as…
-
1
votes1
answer85
viewsHow to return array indices in method
Well I couldn’t find a better title for my case, I have the following function: public function select_tokens() { $sql = "SELECT * FROM `users`"; $select_tokens = Database::DB()->prepare($sql);…
-
1
votes0
answers203
viewsGet JSP foreach value in Jquery to display in label
I would like help to catch a figure that is set within a forEach in my JSP, play for Jquery and it display in a label on the same page. That one forEach retrieves a direct list from the database. I…
-
1
votes1
answer162
viewsAccessing Rasor variables inside a foreach
I am trying to list the contents of a table, showing in each item the items of another table that maintains a relationship with the first (1:N). For this I need 2 select, being the 2nd select based…
-
1
votes2
answers771
viewsSort foreach in php
I made a page that shows the hash in several hash_algos in order to study their differences, but I would like to sort by the hash size and not by the hash_algos name, the code is this, <?php…
-
1
votes1
answer3068
viewsError: Invalid argument supplied for foreach()
I’m having a problem displaying my mailing list, is giving this error: Warning: Invalid argument supplied for foreach() in /###/###/###/view/list.php on line 11 In the file it’s like this: <div…
-
1
votes1
answer587
viewsInsert JSON file into database via PHP
I have a JSON file that I need to do the Insert of the information contained in it in the database. JSON file:…