Jump to content

array problem


desithugg

Recommended Posts

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]
selected
Array ( [0] => 107 [1] => 1322 )
Owned
Array ( [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??
Link to comment
https://forums.phpfreaks.com/topic/18120-array-problem/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/18120-array-problem/#findComment-77671
Share on other sites

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"
Link to comment
https://forums.phpfreaks.com/topic/18120-array-problem/#findComment-77674
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.