Your post does not detail what data is getting duplicated so I can't really address that in this answer. The first part of the code in the while () loop is defining some variables. I think the problem is not the foreach ()/while () but in what you are doing with the. To try to echo an array because you overwrote the value of $key assigned by the foreach. You simply put a foreach () within a while () loop. Immediately after your foreach ($amount as $key) I'm not really sure what you're trying to do, but you are reassigning $key = array() A do-while loop is used when we dont know explicitly how many times the. Objective: All I'm trying to do is foreach $_POST get that rows data from the database and show them and the respective amounts in a table, so the user can confirm the order. A while loop is used when we dont know explicitly how many times the loop should run. The foreach loop - Loops through a block of code for each element in an array. Unfortunately, although I give each form a unique id with a hidden tag, my code only changes the first entry. I'm trying to create a form for each post so that you can like each post. Problem: Each row is being duplicated by the amount of rows there are, so in this case it's returning three rows, but duplicating each one, three times. form in a foreach or while loop Ask Question Asked 6 days ago Modified 4 days ago Viewed 31 times 0 I have a form in a while loop for each post. $amount = $_POST is just an array of the amounts of each item. $_POST is an array of id's that I want to select product info from the database with. so a user selects the item and enter the amount they want of that item, these are sent as arrays to the hander page. Menuju Struktur Kontrol yang Berbeda Pada bagian sebelumnya, kita mempelajari dasar-dasar struktur kontrol di PHP dan kegunaannya dalam pengembangan aplikasi. Context: I have an ordering form, that has a html select and a number input. In PHP, we have the following loop types: while - loops through a block of code as long as the specified condition is true do.while - loops through a. foreach dan banyak lagi Mari kita lihat beberapa struktur kontrol ini dengan contoh. 'FROM blog_categories AS BC INNER JOIN blog_subcategories AS bsc ON bsc.primcat_id = bc.id '. 'SELECT bc.*, GROUP_CONCAT(bsc.subcategory) AS sub_categories '. Something like this: // Made some assumptions with the query, as no schema was posted Your best bet is to create a join between the two tables and step through the rows in one loop, preferably a while loop (vs a do. Secondly you are executing the subcategory query for every iteration of the outer while loop, which means that if your query returns 100 rows, you are issuing 100 queries, not good. while loop which means regardless if a row is found or not, you will step through all the code, so if no row exists in database, you will probably get undefined index errors. There are times where it's ok to have a foreach within a while, but this isn't one of them. Similar to if/else statements, if the given. With the help of loops, you can repeatedly run a PHP code-block until a specific condition occurs. The first three are general-purpose loop constructs, and foreach is used exclusively with arrays. There are times where its ok to have a foreach within a while, but this isnt one of them. I run it and it displays the foreach first randomly. There are four loop statements in PHP: while, dowhile, for, and foreach. I have a categories table with id & category and a sub categories table with a id, subcategory, & primary category id. } while ($row_getCategory = mysql_fetch_assoc($getCategory)) I keep getting a wierd list after running this:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |