Lifelesspeople.com

 Forum FAQsForum FAQs  Knowledge BaseKnowledge Base  RulesRules   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   HostingHosting   RegisterRegister 
 DonateDonate   WikiWiki   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

checking value of fields

 
Lifelesspeople.com Forum Index -> Web Architects' Abode
Post new topic   Reply to topic View previous topic :: View next topic  
Author Message
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2958
Location: Earth

PostPosted: Sat Nov 17, 2007 10:21 am    Post subject: checking value of fields Reply with quote

I know how to do this the extremely long way, but i'm wondering if theres a simpler solution.

I have 6 text fields, all named num1 - num6

I need to make sure that the values in one text fields does not equal the value of another text field

IE: User enters
1 2 3 4 5 6

in the text fields, the values are different, so it does an sql query

if they enter
1 2 3 4 4 5

in them, it comes back saying that you cant have duplicate values and then does nothing else

The only way i know is by using a lot of if statements, but there would be a lot of them doing it that way
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
Scott
tutorialtoday.com


Joined: 24 Mar 2005
Posts: 2582
Location: Mississauga, Ontario

PostPosted: Sat Nov 17, 2007 10:37 am    Post subject: Reply with quote

The easiest way I can think of is something like this:

Code:
$values = array($_POST['num1'], $_POST['num2'], $_POST['num3'], $_POST['num4'], $_POST['num5'], $_POST['num6']);
$dupes = array_count_values($values)
foreach($dupes as $x) {
  if($x > 1) {
    echo 'There is a duplicate....';
  }
}

_________________
Tutorial Management Script - Version 1.3 Released
TutorialToday - Up and running, submit your tutorials!
Linux Tutorials - Coming Soon
Back to top
 
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2958
Location: Earth

PostPosted: Sat Nov 17, 2007 11:02 am    Post subject: Reply with quote

thanks, works perfectly
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
marinaroz
Grey Scaled


Joined: 04 Mar 2004
Posts: 2765
Location: Israel

PostPosted: Sat Nov 17, 2007 3:47 pm    Post subject: Reply with quote

If this is for some kind of interaction with a user, you could write a javascript script to do the testing instead of going to the server. This way you can serve the user an appropriate error message without having the page refreshed.
_________________
Tarakana NET
Back to top
 
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2958
Location: Earth

PostPosted: Sat Nov 17, 2007 3:50 pm    Post subject: Reply with quote

you, its part of a script where there are 6 text fields, where a user has to enter a value between 1 and 20 in each, but not have the same number in any of them

With the example Scott posted, i can seem to work out where to put the sql statement
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
krt
...


Joined: 11 Jan 2005
Posts: 4607
Location: Australia

PostPosted: Sat Nov 17, 2007 4:50 pm    Post subject: Reply with quote

Easier way:
Box 1: <input type="text" name="num[1]" />
Box 2: <input type="text" name="num[2]" />
Box 3: <input type="text" name="num[3]" />
...

PHP:
Code:
$array = $_POST['num'];
if (count($array) != count(array_unique($array))) {
   // Duplicate found
}
Back to top
 
Display posts from previous:   
Post new topic   Reply to topic    Lifelesspeople.com Forum Index -> Web Architects' Abode All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Home | Hosting | News | Forum | Links | System Status | About | Archive | Donate ]
Powered by phpBB © 2001, 2002 phpBB Group
All trademarks and copyrights on this page are owned by their respective owners. Posts and comments are owned by the poster. Everything else © 2001 - 2007 Lifelesspeople.com