Page 1 of 1

Help with array

Posted: Sat Jul 14, 2007 9:50 am
by hesham2012
Hello everyone

i have a page which lets the user choose from "select form list/menu" a number of fields that he will fill for example the user is

asked 'how many children you have?'

maybe he has 1 ,2,12 or 20 whatever he choosed the number from list/menu. after he choosed the number he goes to another

page with number of 'inputs text form' as he choosed before. now he will enter his children names i want to be sure he inserted

every name just one time no duplicated names but in the same thime i don't know how many input fields i have, every one has a

different number of children so i think it will be a good idea if i can put all names in an array and use array_unique then count the

two arrays if the numbers are different sure there is a duplicated names


if any one can help me to carry htis out or has a better idea i'll appreciate this thanks

Posted: Sat Jul 14, 2007 12:38 pm
by ankhmor
Array_unique is not a solution, because it's just gonna remove the duplicate names.
I think what you should do is to check every name if it matches any other names.
you can use preg_match or just ==.
And to do so put your process into a double loop like

Code: Select all

while(){
while(){

}
}

Posted: Sat Jul 14, 2007 2:03 pm
by califdon
May I suggest a different approach: display just one Input box at a time, with two buttons below it: "Enter Another" and "Finished". It's easier to program and it's easier for the user.

Posted: Sat Jul 14, 2007 2:04 pm
by Benjamin
What if I have two kids named Joe?

Posted: Sat Jul 14, 2007 2:08 pm
by superdezign
astions wrote:What if I have two kids named Joe?
Poor Joe. Joe is always mistaken for Joe.

Posted: Sat Jul 14, 2007 9:59 pm
by ankhmor
I don't think that its alowed to name two of your kids the same name. Is it?
And anyways one will be younger and another one will be older.

Posted: Sun Jul 15, 2007 4:54 am
by Ollie Saunders
ankhmor wrote:I don't think that its alowed to name two of your kids the same name. Is it?
Why wouldn't it be allowed?

Posted: Sun Jul 15, 2007 7:06 am
by superdezign
ankhmor wrote:I don't think that its alowed to name two of your kids the same name. Is it?
And anyways one will be younger and another one will be older.
You could names two twins Joseph and call one by Joe and one by Joey. You can tell them apart by nickname, but professionally, you would write their actual name, not their nickname.

Posted: Sun Jul 15, 2007 9:07 am
by hesham2012
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Thank you all i did something like this and worked 100%


Post input name L1,L2,L3 ....

Code: Select all

<?php
 for($i=1;$i<=$_POST[x];$i++)
 {
 $f=$i+1;
 $a=$_POST[("L".$i)];
 	for($x=$f;$x<=$_POST[x];$x++)
	 {
	$b=$_POST[("L".$x)];
	if($a==$b){echo"One or more name is duplicated";}
	}
  }
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]