nzrubin
asked on
compare variable to array PHP
Hello guys
i cannot find answer at the simple question how to compare variable to array.
for example i have some data from database
"one", "two", "three", "four", "five".
and i need to do:
if ($some_var = "two" and "three")
{
execute some code
}
is it possible to comapre $some_var with some array that i retreive from database without looping? just to get what i need...
i cannot find answer at the simple question how to compare variable to array.
for example i have some data from database
"one", "two", "three", "four", "five".
and i need to do:
if ($some_var = "two" and "three")
{
execute some code
}
is it possible to comapre $some_var with some array that i retreive from database without looping? just to get what i need...
ASKER
thanks for quick reply
i m trying to separate "customers" so they can see only particular projects, but sometimes customers can see the same projects:
for exml:
cust1 can see 1,2,3
cust2 can see 4
cust3 can see 1,3,4.
if ($roww->permission == 'Customer')
{
$result_cust = mysql_query("SELECT * FROM pr_cust_permiss WHERE username = '$username'");
while ($row_cust = mysql_fetch_object($result _cust))
{
$var = ???????????????????????? some array or something???;
} // end while
//// select data for customers they can see only particular info which id located in "pr_cust_permiss" table
$result = mysql_query("SELECT * FROM pr_projects WHERE proj_id = '$var' ORDER BY proj_id DESC");
} //end if = customer, else following
else
{
//// select all data
$result = mysql_query("SELECT * FROM pr_projects ORDER BY proj_id DESC");
}// end else
i m trying to separate "customers" so they can see only particular projects, but sometimes customers can see the same projects:
for exml:
cust1 can see 1,2,3
cust2 can see 4
cust3 can see 1,3,4.
if ($roww->permission == 'Customer')
{
$result_cust = mysql_query("SELECT * FROM pr_cust_permiss WHERE username = '$username'");
while ($row_cust = mysql_fetch_object($result
{
$var = ???????????????????????? some array or something???;
} // end while
//// select data for customers they can see only particular info which id located in "pr_cust_permiss" table
$result = mysql_query("SELECT * FROM pr_projects WHERE proj_id = '$var' ORDER BY proj_id DESC");
} //end if = customer, else following
else
{
//// select all data
$result = mysql_query("SELECT * FROM pr_projects ORDER BY proj_id DESC");
}// end else
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
O MAN!!!!!!!!!!!!!! OSANA!!!!!!!!!!!!!!!!!!!!! !
thanks very much!!!!!!!!!!!!
thanks very much!!!!!!!!!!!!
On second thought, this will combine both queries and save the time of building the array in the while loop. Much more elegant, and quicker.
if ($roww->permission == 'Customer')
{
$result = mysql_query("SELECT $ FROM pr_projects WHERE proj_id IN (SELECT proj_id FROM pr_cust_permiss WHERE username = '$username') ORDER BY proj_id DESC");
} //end if = customer, else following
else
{
//// select all data
$result = mysql_query("SELECT * FROM pr_projects ORDER BY proj_id DESC");
}// end else
ASKER
thanks very much!
ASKER
thats great! last one !!!
ASKER
it works work!!!!!!!!!!!!!
If you can show us what you're working with, we can help in a more specific manner. Can you share your code with us? What are you working with in your query results? What exactly are you trying to compare those results to?
Open in new window