desithugg Posted August 20, 2006 Share Posted August 20, 2006 umm im having trouble checking if all the items selected in a form are all owned by the selecter.[code]$my_items = $_POST['my_items'];$other = $_POST['other'];$other_items = $_POST['other_items'];$link = mysql_connect('localhost', $my_sql_password, $my_sql_username);if (!$link) { die('Could not connect: ' . mysql_error());}$db_selected = mysql_select_db('osiris_thugg');if (!$db_selected) { die('Could not select database: ' . mysql_error());}$query = "SELECT item_id FROM items where owner = '$user_currently_loged'"; $result = mysql_query($query) or die(mysql_error());while($row = mysql_fetch_assoc($result)){$my_check1[] = $row['item_id'];}$query = "SELECT item_id FROM items where owner = '$other'"; $result = mysql_query($query) or die(mysql_error());while($row = mysql_fetch_assoc($result)){$other_check1[] = $row['item_id'];}if(count(array_intersect($my_items, $my_check1)) != count($my_items)) {echo"One or more of the items selected never did or does not belong to you.";Echo"selected<br>";print_r(array_values($my_items));echo"Owned<br>";print_r(array_values($my_check1));exit;}[/code]Okay the items i selected were all owned by the two people"$other","$user_currently_loged" but it still gives me that error to make sure i selected the right items i added [code]Echo"selected<br>";print_r(array_values($my_items));echo"Owned<br>";print_r(array_values($my_check1));[/code]and it showed me that i had selected the right items.it showed me[code]selectedArray ( [0] => 107 [1] => 1322 ) OwnedArray ( [0] => 10 [1] => 11 [2] => 12 [3] => 16 [4] => 23 [5] => 24 [6] => 30 [7] => 107 [8] => 1322 )[/code]so you can see i selected the ids 107 and 1332 and they are both owned by that selecter yet it keeps giving me that error.can any1 see an error?? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 20, 2006 Share Posted August 20, 2006 Maybe this will help:[code]$my_items = $_POST['my_items'];$other = $_POST['other'];$other_items = $_POST['other_items'];$link = mysql_connect('localhost', $my_sql_password, $my_sql_username) or die(mysql_error());$db_selected = mysql_select_db('osiris_thugg') or die(mysql_error());$query = "SELECT COUNT(item_id) FROM items WHERE owner = '$user_currently_loged' AND item_id IN (" . implode(", ", $my_items) . ")";$result = mysql_query($query) or die(mysql_error());$count = mysql_result($result, 0);if ($count != count($my_items)) { echo"One or more of the items selected never did or does not belong to you."; Echo "selected<br>"; print_r(array_values($my_items)); echo"Owned<br>"; echo $count; exit;}[/code] Quote Link to comment Share on other sites More sharing options...
Barand Posted August 20, 2006 Share Posted August 20, 2006 Odd ???If I run this[code]<?php$my_items = array (107,1322) ;$my_check1 = array (10 , 11 , 12 , 16 , 23 , 24 , 30 , 107 ,1322) ;if(count(array_intersect($my_items, $my_check1)) != count($my_items)) {echo "One or more of the items selected never did or does not belong to you.";}else echo "OK" ;?>[/code]It says "OK" Quote Link to comment Share on other sites More sharing options...
desithugg Posted August 20, 2006 Author Share Posted August 20, 2006 yes i know but it is but i tried hitman6003's idea and it works perfect :) thnx Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.