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?
checking multiple variables
Started by coolaid, May 11 2006 02:02 AM
8 replies to this topic
#1
Posted 11 May 2006 - 02:02 AM
#2
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
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.
$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
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
Posted 11 May 2006 - 02:13 PM
coolaid, 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?
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
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.
i'll have to read up on arrays, and foreach, and fors. but i'll come back with results.
#7
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
)
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
Posted 12 May 2006 - 01:29 AM
coolaid, 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.
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
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
