Skip to content
Home » [Update] ขอถามเรื่องการ insert ข้อมูลแบบวนลูปด้วย foreach คือผมมีเรื่องอยากถามครับ | each ตามด้วย – NATAVIGUIDES

[Update] ขอถามเรื่องการ insert ข้อมูลแบบวนลูปด้วย foreach คือผมมีเรื่องอยากถามครับ | each ตามด้วย – NATAVIGUIDES

each ตามด้วย: คุณกำลังดูกระทู้

 

ขอถามเรื่องการ insert ข้อมูลแบบวนลูปด้วย foreach คือผมมีเรื่องอยากถามครับ

 

เริ่มหัวข้อใหม่



R_akK_Et

โพสกระทู้ (
120 )

บทความ (
0 )



คือผมมีเรื่องอยากถามครับ ผมได้ทำการดึงข้อมูลออกมาจากตารางเป็นแบบ array แล้วผมต้องกานเพิ่มข้อมูลลงในอีกตารางนึง โดยใช้ foreach แต่ผล คือ มัน เพิ่มข้อมูลให้แค่ เรคคอดเดียว ผมจึงอยากถามคนที่รู้ว่าจะต้องทำยังไงครับถึง จะเพิ่มข้อมูล ด้วยforeachได้ ขอตัวอย่างหน่อยครับ

Tag : – – – –

 

Date :
2010-03-22 14:22:19
By :
rakket
View :
2614
Reply :
10

 

 

No. 1



ultrasiam

โพสกระทู้ (
1,268 )

บทความ (
0 )

เอาโค้ดมาดูด้วยดีไหมคะ
ถ้าจำไม่ผิด foreach มันจะ loop ดาต้าออกมาจาก array ทีละตัว ถ้ามองในมุมฐานข้อมูลก็คือ ทีละคอลัมน์หรือฟิวด์
ที่คุณต้องทำคือ ให้มัน loop record ด้วยค่ะ ส่วนใหญ่จะนิยม ใช้ while มากกว่า

Date :
2010-03-22 14:52:39
By :
ultrasiam


 


 

No. 2



R_akK_Et

โพสกระทู้ (
120 )

บทความ (
0 )

ผมคิดว่าforeach มันดึงข้อมูลมาแบบอาเรย์ ก็น่าจะเพิ่มข้อมูลได้อ่ะครับ

แสดงว่าต้องใช้ while เสริมด้วยใช้มั้ยครับ – -a

ขอบคุณมากครับ

Date :
2010-03-22 15:07:51
By :
rakket


 


 

No. 3



ultrasiam

โพสกระทู้ (
1,268 )

บทความ (
0 )

เอาโค้ดมาดูด้วยชัวร์กว่าค่ะ จินตนาการแบบนี้อาจจะเข้าใจไปคนละทางได้

Date :
2010-03-22 15:09:50
By :
ultrasiam


 


 

No. 4



ultrasiam

โพสกระทู้ (
1,268 )

บทความ (
0 )

ต้องดูด้วยว่าตอนคุณดึงข้อมูลมาเป็น array นั้น ดึงมาแบบไหน มาหมดทุก record หรือว่ามาแค่ record เดียว

Date :
2010-03-22 15:11:27
By :
ultrasiam


 


 

No. 5



R_akK_Et

โพสกระทู้ (
120 )

บทความ (
0 )

คือ ผมตอนแรกผม ประกาศให้ เรียกใช้ ฟังชั่นนี้
Code (PHP)

function getListquestionpage()
	{
			global $conn;		
	     	//$sql  		  = "SELECT c.id as qid, name, question_id, description, fullsccres  FROM question_categories_tb as c INNER JOIN question as q ON c.id = question_id  "
			//$result       = &$conn->Execute( "SELECT c.id as cid, c.name, c.question_id, c.fullsccres , q.id as qid,q.question_id, q.title, q.fullsccres FROM question_categories_tb as c INNER JOIN question a q ON c.id = q.question_id  ");
			$conn -> Execute ( "set names 'utf8'");
			$result       = &$conn->Execute( "SELECT q.id as questionid, c.id as parentid, q.title, q.fullsccres as qscore,	c.name,	c.fullscores as cscore	FROM question_tb as q INNER JOIN question_categories_tb as c ON q.question_id =  c.id  ORDER BY c.id");
			while (!$result->EOF) {

		$thisref[$result->fields['parentid']]['id'] 		= $result->fields['parentid']; 
		$thisref[$result->fields['parentid']]['name'] 	    = $result->fields['name']; 
		$thisref[$result->fields['parentid']]['cscore']     = $result->fields['cscore']; 

		$arr_questions['title']			= $result->fields['title']; 
		$arr_questions['qscore']   		= $result->fields['qscore']; 
		$thisref[$result->fields['parentid'] ]['questions'][ $result->fields['questionid'] ] = $arr_questions;								
				$result->MoveNext();			
			}			
			return $thisref;
}

function getListbranch()
{
		global $conn;
		$result       = &$conn->Execute( "SELECT * FROM brance_tb");
			while (!$result->EOF) {
			
			if($result->fields['branceh_id'] > 0) {
				$refs[$result->fields['branceh_id']]['id']			=		$result->fields['branceh_id']; 
				$refs[$result->fields['branceh_id']]['name']		=		$result->fields['branceh_name']; 
				$refs[$result->fields['branceh_id']]['bm_id']		=		$result->fields['bm_id']	;
				$refs[$result->fields['branceh_id']]['email']		=		$result->fields['email']	;
				$refs[$result->fields['branceh_id']]	['address']  =		$result->fields['address']	;
				$refs[$result->fields['branceh_id']]['tel']			=		$result->fields['tel']	;
				
				}
						$result->MoveNext();
			}
			return $refs;
}


เวลาเรียกใช้
Code (PHP)

$r = getListquestionpage();
$a = getListbranch();


จากนั้น ผมก็เขียน foreach เพื่อเรียกใช้
Code (PHP)

 <?php
				  		$i=1;
				  		foreach($r as $key => $value){
						
						
						  
				 ?>
                  <tr class="style16">
                    <td width="44" height="33" class=""><div align="left" class="style19">
                        <div align="center" class="s"><?php echo $i;?>
                          <input type="hidden" name="scoretest1[<?php echo $key ?>]" id="scores" value="<?php echo $i;?>"  />
                        </div>
                    </div></td>
                    <td width="618" align="center" class=""><table cellspacing="0" cellpadding="0">
                        <tr>
                          <td height="24" align="left" width="571"> <?php echo $value['name'] ?></td>
                        </tr>
                      </table>                       </td>
                    <td width="42"><div align="center" class="style19">
                        <div align="center" class="style16">
						<?php echo $value['cscore'] ?>
                        <input type="hidden" name="scoretest[<?php echo $key ?>]" id="score" value="<?php echo $value['cscore'] ?>"  />
                        </div>
                    </div></td>
                    <td colspan="2" class="style16"><div align="center" class="style19">
                        <div align="center" class="style16">ได้</div>
                    </div></td>
                  </tr>
                  <?php 
				  	$x=1;
				  	foreach($value['questions'] as $key2 => $value2){ 
					
					?>
                  <tr class="style23">
                    <td class="style23"><div align="right"><span class="s">
                      <input type="hidden" name="scores2" id="scores2" value="<?php echo $x;?>"  />
                    </span><?php echo $x ?></div></td>
                    <td class="style23">
                    <table cellspacing="0" cellpadding="0">
                          <tr>
                            <td height="23" align="left" width="571"><?php echo $value2['title'] ?></td>
                          </tr>
                      </table></td>
                    <td class="style21"><div align="center"><?php echo $value2['qscore'] ?></div></td>
                    <td colspan="2" class="style21"><div align="center">
                      <input type="checkbox" name="checkbox2[<?php echo $key2 ?>]" id="checkbox2[<?php echo $key2 ?>]" value="<?php echo $value2['qscore'] ?>"  />
                    </div></td>
                  </tr>
                  
                 
                  <?php  $x++;	
				  			}
				  		$i++; 
						}
					?>


แล้วก็ให้มันอยู่ในรูปแบบ $_POST เพื่อนำไปลงฐานข้อมูล
Code (PHP)

if($_POST){

	 foreach($_POST['scoretest'] as $id => $sum2){
 		$fullscore += $sum2 ;	
	 }
	 		
	foreach($_POST['checkbox2'] as $key => $sum){
 		$sumscore += $sum ;	
	}
		$gscore = ($sumscore*100)/$fullscore;
		
		
	
$bmid = insertUserbm(StripExtraSpace($_POST['name']),$_POST['position']);
$evid = insertEvaluate($bmid, $_POST['Branch'], $fullscore, $sumscore, $gscore,$_POST['date'],$_POST['time']);

สรุปคือผมต้องการที่จะกลับมาตรวจสอบใหม่ได้ โดยที่เหมือนต้นฉบับเวลา insert เพื่อเอาไปทำเป็น Report ผมจึงจำเป็นต้อง insert แบบลูป ซึ่งไม่แน่ใจว่าใช้ foreach รึเปล่า ยังไงก็ให้คำแนะนำด้วยนะครับ
ติดที่เดียว T^T ขอโทดนะครับที่ถามซับซ้อน พึ่ง เรียน php มา 3 อาทิตย์ เลยทำให้บางอย่างยังไม่รู้

Date :
2010-03-24 16:43:15
By :
rakket


 


 

No. 6



R_akK_Et

โพสกระทู้ (
120 )

บทความ (
0 )

– – – – – – – – – – -สงสัยคงไม่ได้ จริงๆ มั้ง

Date :
2010-03-25 09:23:46
By :
rakket


 


 

No. 7



R_akK_Et

โพสกระทู้ (
120 )

บทความ (
0 )

ใครพอรู้มั้ง ก็ช่วย อธิบายหน่อย สิ ไม่ต้องเเอาของผมก็ได้ แต่ขอใกล้เคียง แบบคร่าวๆ
*ตอนนี้ผมข้ามไปทำฟอร์มที่2 แล้ว จอยข้อมูลกัน 5 ตาราง สนุกจิงๆ

Date :
2010-03-25 11:42:51
By :
rakket


 


 

No. 8



เอี่ยว

โพสกระทู้ (
3,468 )

บทความ (
0 )

ผมไม่ได้อ่านโค้ดนะครับ ตาลาย

จะบันทึกอะไรในลูปก็บันทึกได้ตามสบายคับ เช่น

$a[] = ‘a’;
$a[] = ‘b’;

foreach ($a as $key => $val)
{
mysql_query(“INSERT INTO ur_table SET col1=$key, col2=’$val'”);
}

แค่นี้ก็บันทึกไปสองเรคคอร์ดแล้วคับ

Date :
2010-03-25 12:14:30
By :
pjgunner


 


 

No. 9



R_akK_Et

โพสกระทู้ (
120 )

บทความ (
0 )

ครับ ขอบคุณมากครับ แล้วผมจะนำไปประยุก ใช้ครับ

Date :
2010-03-25 13:07:24
By :
rakket


 


 

No. 10



ลูฟิ่

โพสกระทู้ (
251 )

บทความ (
0 )

<input type=”text” name=”a[]” size=”10″/>
<input type=”text” name=”b[]” size=”10″/>

foreach($_POST[‘dimension’] as $key=>$val)
{

$sql2 = “insert into table(a,b) values (‘”.$_POST[a][$key].”‘,”.$_POST[b][$key].”‘)”;
mssql_query($sql2);

}

Date :
2010-03-25 13:48:38
By :
paphun


 

 
 

ค้นหาข้อมูล

   

 

แสดงความคิดเห็น

Re :
ขอถามเรื่องการ insert ข้อมูลแบบวนลูปด้วย foreach คือผมมีเรื่องอยากถามครับ

 

 

รายละเอียด



 







































เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]….[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ

อัพโหลดแทรกรูปภาพ
ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

 
 

 

เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง

 

โดย

อีเมล์

บวกค่าให้ถูก

<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)

[NEW] การใช้ both/ both of, either/ either of, neither/ neither of | each ตามด้วย – NATAVIGUIDES

1. การใช้ both, either, และ neither เมื่อพูดถึงสิ่งของสิ่งเดียวกัน และสามารถใช้คำทั้งสามนี้ร่วมกับคำนาม (Nouns) ได้ดังตัวอย่าง

                Both restaurants are very good.

                We can go to either restaurant. I don’t care. (either หมายความว่า one or the other หรือ it doesn’t matter which one)

                Neither restaurant is expensive. (neither หมายความว่า  not the one or not the other)

                I didn’t like either restaurant. (= not the one or the other)

2. สามารถใช้ both/ either/  neither กับ of และเมื่อใช้คำทั้งสามนี้กับ of จำเป็นต้องมี the/ these/ those/ my/ your/ his, etc. ตามหลัง of  เสมอไป อย่างเช่น จะใช้ว่า both of restaurants ไม่ได้ แต่ต้องใช้ว่า both of the restaurants หรือ both of these restaurants เป็นต้น ดังตัวอย่าง

                Both of your cars are very nice.

                Neither of the restaurants we went to was (or were) expensive.

                We can go to either of those restaurants. I don’t mind.

หมายเหตุ: สำหรับ both  อาจใช้ of  ตามหลังหรือไม่ต้องใช้ก็ได้ เช่น : both my parents หรือ both of my parents.

3. สามารถใช้ us/ you/ them ต่อท้าย both of/ neither of/ either of ได้เช่นเดียวกัน  ดังตัวอย่าง

                Can either of you speak Spanish?

                I wanted Tom and Ann to come, but neither of them wanted to.

                ต้องใช้ both of ข้างหน้าของ us/ you/ them เสมอไป  ดังตัวอย่าง

                Both of us were very tired.

4. ข้างหลังของ neither of สามารถใช้ได้ทั้ง Singular Verb (กริยาเอกพจน์) หรือ Plural Verb (กริยาพหูพจน์) เช่น  :

                Neither of the children wants (or want) to go to bed.

                Neither of us is (or are) married.

 

 

 

5. สามารถใช้รูปแบบ both and , neither nor, และ either or  ได้ดังตัวอย่าง

                Both Tom and Ann were late.

                They were both tired and hungry.

                Neither Tom nor Ann came to the party.

                He said he would contact me, but he neither wrote nor called.

                I’m not sure where he is from.  He is either Spanish or Italian.

                Either you apologize, or I’ll never speak to you again.

6. สามารถใช้ both/ neither/ either โดยลำพังก็ได้เช่นเดียวกัน  ดังตัวอย่าง

                Is he British or American? Neither.  He is Australian.

                Do you want tea or coffee?  Either.  It doesn’t matter.

                I couldn’t decide which one to choose.  I liked both.

Share this:

Like this:

ถูกใจ

กำลังโหลด…


How we read each other’s minds | Rebecca Saxe


http://www.ted.com Sensing the motives and feelings of others is a natural talent for humans. But how do we do it? Here, Rebecca Saxe shares fascinating lab work that uncovers how the brain thinks about other peoples’ thoughts and judges their actions.\r
\r
TEDTalks is a daily video podcast of the best talks and performances from the TED Conference, where the world’s leading thinkers and doers give the talk of their lives in 18 minutes. TED stands for Technology, Entertainment, Design, and TEDTalks cover these topics as well as science, business, development and the arts. Closed captions and translated subtitles in a variety of languages are now available on TED.com, at http://www.ted.com/translate. Watch a highlight reel of the Top 10 TEDTalks at http://www.ted.com/index.php/talks/top10

นอกจากการดูบทความนี้แล้ว คุณยังสามารถดูข้อมูลที่เป็นประโยชน์อื่นๆ อีกมากมายที่เราให้ไว้ที่นี่: ดูความรู้เพิ่มเติมที่นี่

How we read each other's minds | Rebecca Saxe

Recommend each other. Why should the other go? [2Days \u0026 1Night Season 3/2018.04.15]


Click the \”Caption\” button to activate subtitle!
Cast: Cha Taehyun(차태현), Kim Jongmin(김종민), Kim Junho(김준호), Defconn(데프콘), Yoon Siyoon(윤시윤), Jung Joonyoung(정준영)

2d1n 2Days\u00261Night_Season3 oppa 😍🖐2d1n_ep692
2Days \u0026 1Night Season3 sub eng : Spring Trip to Bogildo Island Part 2

▶Subscribe KBS World Official Pages
Youtube Subscribe:https://www.youtube.com/kbsworld
Homepage: http://www.kbsworld.co.kr
Facebook: http://www.facebook.com/kbsworld
Twitter: http://twitter.com/kbsworldtv
Instagram: https://www.instagram.com/kbsworldtv/
Line: https://goo.gl/g5iRQV
Android Download : http://bit.ly/1NOZFKr
IOS Download : http://apple.co/1NktctW

Recommend each other. Why should the other go?  [2Days \u0026 1Night Season 3/2018.04.15]

each, every, all, another, other ใช้อย่างไร บวกนามเอกพจน์หรือพหูพจน์ by ดร.พี่นุ้ย


each, every, all, another, other ใช้อย่างไร บวกนามเอกพจน์หรือพหูพจน์ by ดร.พี่นุ้ย
ดร.พี่นุ้ย สมิตา หมวดทอง
โรงเรียนสอนภาษาอังกฤษ NuiEnglish
เกียรตินิยมอันดับ 1 อักษร จุฬาฯ
นักเรียนทุน ก.พ. และทุนรัฐบาลอังกฤษ
พสบ. 26 กองทัพบก
พรส.13 โรงเรียนเสนาธิการทหารบก
พขส.2 สถาบันพระปกเกล้า
FA 7 สถาบันพระปกเกล้า
พคบ.10 กอ.รมน
กรรมการสงเคราะห์ สถานพินิจสมุทรสาคร
The Startup Ready Batch3
SIP 44 ธนาคารกรุงเทพ
http://www.nuienglish.com
http://www.facebook.com/nuienglish
stayhome withme

each, every, all, another, other ใช้อย่างไร บวกนามเอกพจน์หรือพหูพจน์ by ดร.พี่นุ้ย

AQUARIUS: \”EXTREME PASSION! YOU BLOW EACH OTHERS MINDS!!!!\” 🔥 🤯AUGUST 2021 LOVE TAROT


Aquarius Tarot
💗To Book a Personal Reading link to my website 💗
https://baddisonintuitivetarot.com/
Just remember to email me your love question and a brief description surrounding your love question followed by the zodiac signs of you and your person (just two people per reading).
If you feel the reading has resonated with you, here is a link to my Vimeo where I will be posting extended clips!
NO EXTENDED FOR THIS VIDEO
Join Ramblin mikes tarot meet n greet where I will be guest reading in Palm coast Florida on November 6th 2021 🌟
https://ramblinmike.kartra.com/page/meetandgreet
Cards that I use in this reading include: (You will be taken to Amazon where I purchased mine)
Infamous Mystical cat deck by Lunaea Weatherstone https://amzn.to/2ySWp2f (The mystical cat deck is my main clarifying deck 🐱
\”The Gilded Tarot\” by Barbara Moore and Ciro Marchetti https://amzn.to/2WV8U5c
The Rider Waite by Arthur Edward Waite https://amzn.to/2ySJIo9
Please hit the Like button, the notification bell and SUBSCRIBE 🙂
Welcome to Baddison Intuitive Tarot. I’m an Empath along with being an intuitive tarot reader. I use the cards as a baseline and allow my guides to reveal the rest so sometimes I won’t be using the cards \”definition\” but what spirit wants me to say.

This channel is a place for no judgment or hate, so negativity is not welcomed here. A great place for tarot reading beginners as I also love to teach my viewers how to read tarot intuitively as I explain each card in a way that makes understanding tarot easy or how to read tarot on yourself or for others.

These are free general LOVE readings.
Any donations are not expected but GREATLY appreciated and Please note \”donation\” in the \”+Add a note\” section: at https://paypal.me/baddisontarot
Or Cashapp $baddison77 again, very appreciated.
Tarot Decks I’d Love to Use for the Channel 🙂
https://www.amazon.com/hz/wishlist/ls…
Disclaimer:
Tarot readings are for entertainment purposes only and should NEVER take the place of psychological, medical, legal, or financial professional services. Baddison Intuitive Tarot accepts no liability or responsibility for any action a client chooses to take.

AQUARIUS: \

Audi Q4 sportback e-tron review – an electric car to fit every lifestyle? Price, specs and driving


Welcome to my review of the Audi Q4 sportback etron. Based on the Audi Q4, the sportback is more of a coupé inspired model, although the more curved styling doesn’t cramp interior space. In this video we look at:
exterior walkaround
options
prices
practicality
interior front and back
driver features
drive along
I hope you enjoy this video. If you do, please give it a like! Please also hit subscribe.
audi audiq4 audiq4etron electric ev electriccar electriccars familycar carreview cars

Audi Q4 sportback e-tron review - an electric car to fit every lifestyle? Price, specs and driving

นอกจากการดูบทความนี้แล้ว คุณยังสามารถดูข้อมูลที่เป็นประโยชน์อื่นๆ อีกมากมายที่เราให้ไว้ที่นี่: ดูวิธีอื่นๆLEARN FOREIGN LANGUAGE

ขอบคุณมากสำหรับการดูหัวข้อโพสต์ each ตามด้วย

Leave a Reply

Your email address will not be published. Required fields are marked *