954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

count value in foreach

this is my code

i wanna insert value starting with cb into no table coming from form. but i cannot count $a (just starting with cb) value

foreach($_GET as $a=>$b){
		$q1 = "UPDATE no SET drm = 1,
								s = '$time',
								h	= '$dest'
							WHERE 
								s = '$b'";
		$q2	= "UPDATE no_ta SET gsayi=gsayi+$x";

								
						
		if(!mysql_query($q1) || !mysql_query($q2)){
				echo "Hata No : ".mysql_errno()."<br/> Hata Mesajı :".mysql_error();
				
			}	
	}


data coming from from like following

hedef-zodehala
button-Gonder
cb1-6319039
cb2-8151977
cb3-8151977
cb4-6914312
cb5-7749106
cb6-6622528
cb7-5707214


for example when i usedcount($a) result is 1111111 (seven one) in fact it must be just 7. how can i do it

zodehala
Newbie Poster
8 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

where do you get $x?

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

$x is the sum of form objects that begin with cb

zodehala
Newbie Poster
8 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

I assume that this is set somewhere before the loop

Why are you using $_GET? $_POST would be more tidy. I don't think you want all that data in the url.

Show your form.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

what count() did you use? php count or sql count? I assume you use the php count, so the reason why it displayed 1111111 is because you put the php count() inside the loop

vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 

i am using php count in loop

zodehala
Newbie Poster
8 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

show your form

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

i don't even see the count() function on your code lol

vaultdweller123
Posting Pro
554 posts since Sep 2009
Reputation Points: 42
Solved Threads: 75
 

OK, I'm bugging out. Good luck. Stone, blood and getting are terms which spring to mind. :(

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

i sayed something but it didn't aplay

pzuurveen
Posting Whiz in Training
229 posts since Sep 2006
Reputation Points: 32
Solved Threads: 47
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You