Jump to content


checking multiple variables


8 replies to this topic

#1 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 11 May 2006 - 02:02 AM

on my forums i have a re-order script and for each forum, thers a variable corresponding to its name, e.g 'orderid_1', 'orderid_2', 'orderid_3', etc.

how can i check if any of the variables are the same as one another?

i cant use something as simple as if $var1 == $var2 || $var1 == $var3 becasue the numer of variables is dynamic.

so.. any ideas on how i could do this?

#2 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 11 May 2006 - 04:56 AM

I don't understand what you are asking, can you elaberate more? Why can't you use simple if conditions?

#3 Futingkiller

    Young Padawan

  • Members
  • Pip
  • 110 posts

Posted 11 May 2006 - 06:52 AM

the only way to verify them is by using an array and make a boolean general variable. you verify with a for (or while) (or foreach) if every $var[$i] is == with $var[$j]. so you besicaly need an array named $var.
$ok=true;
for($i=0;$i<"value here";$i++)
for($j=0;$j<"value here";$j++)
if($var[$i]!=$var[$j]) ok=false;
you can use something like that.

#4 Wybe

    Jedi In Training

  • Members
  • PipPip
  • 399 posts
  • Gender:Male
  • Location:the Netherlands
  • Interests:Graphic design, digital and traditional, street style, graffiti, guerilla drawing, typography, coding, sex

Posted 11 May 2006 - 09:55 AM

if(array_unique($array)===$array) {
echo 'No duplicate items';
} else {
echo 'Duplicate items, yeah yeah';
}

you could use === or ==. I haven't tested this little snippet yet, it's made especially for you :)

#5 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 11 May 2006 - 02:13 PM

View Postcoolaid, on May 11 2006, 07:01 AM, said:

on my forums i have a re-order script and for each forum, thers a variable corresponding to its name, e.g 'orderid_1', 'orderid_2', 'orderid_3', etc.

how can i check if any of the variables are the same as one another?

i cant use something as simple as if $var1 == $var2 || $var1 == $var3 becasue the numer of variables is dynamic.

so.. any ideas on how i could do this?

if you're wanting to only pull unique enties from a database try:

SELECT DISTINCT orderid FROM order_db;


#6 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 11 May 2006 - 02:37 PM

na, na, na, im trying to check vars. vor unique values to insert into the db.

i'll have to read up on arrays, and foreach, and fors. but i'll come back with results.

#7 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 11 May 2006 - 04:39 PM

*bump*
whew.. after a couple hours i finished the script!! i had to learn how to use arrays and how to create em (never used them before)

so thanks wybe and Futingkiller! (nice try spaceghost :))

#8 Hayden

    P2L Jedi

  • Members
  • PipPipPip
  • 716 posts
  • Gender:Male
  • Location:Texas

Posted 12 May 2006 - 01:29 AM

View Postcoolaid, on May 11 2006, 07:37 PM, said:

na, na, na, im trying to check vars. vor unique values to insert into the db.

i'll have to read up on arrays, and foreach, and fors. but i'll come back with results.

then do just the opposite.

SELECT * TABLE WHERE var="value"

then check the size with mysql_num_rows, if it equals zero then there's no value present otherwise it already has the values.

#9 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 12 May 2006 - 03:17 AM

the thing is, i need(ed) to check the values before i insert them into the database to prevent duplicate entries.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users