undersun Posted February 12, 2011 Share Posted February 12, 2011 Hi, I'm trying to combine and sort two tables so I can display the output as one. And I'm getting the error "PHP Warning: array_multisort() [<a href='function.array-multisort'>function.array-multisort</a>]: Array sizes are inconsistent in ... on line 282". Line 282 is "array_multisort($tmp_name, SORT_ASC, $details);". I'm a self taught beginner coder and I know that my coding is often very clumsy and so that is probably the problem. Any help to solve this error would be greatly appreciated. Cheers $sql = "SELECT * FROM db_user LEFT JOIN db_details ON db_details.details_id = db_user.user_details_id WHERE db_user.user_id = '" . $user_id . "'"; $result = mysql_query($sql); $num = mysql_num_rows($result); if ($num != NULL) { for ($i = 0; $i < $num; $i++) { $user_group_id = mysql_result($result, $i, "db_user.user_group_id"); $details_id = mysql_result($result, $i, "db_details.details_id"); $details_name = mysql_result($result, $i, "db_details.details_name"); $details[] = array($details_id, $details_name, $user_group_id); } } $sql = "SELECT * FROM db_members LEFT JOIN db_details ON db_details.details_id = db_members.members_details_id WHERE db_members.members_user_id = '" . $user_id . "'"; $result = mysql_query($sql); $num = mysql_num_rows($result); if ($num != NULL) { for ($i = 0; $i < $num; $i++) { $members_group_id = mysql_result($result, $i, "db_members.members_group_id"); $details_id = mysql_result($result, $i, "db_details.details_id"); $details_name = mysql_result($result, $i, "db_details.details_name"); $details[] = array($details_id, $details_name, $members_group_id); } } foreach ($details as $key => $val) { $tmp_name[$key] = $val[1]; } array_multisort($tmp_name, SORT_ASC, $details); Link to comment https://forums.phpfreaks.com/topic/227447-php-warning-array_multisort/ Share on other sites More sharing options...
undersun Posted February 14, 2011 Author Share Posted February 14, 2011 I've reread the PHP manual for 'array_multisort' (http://php.net/manual/en/function.array-multisort.php) and I still can't see what I've done wrong. The actual code seems to work on the site but every time it's run it throws up an error and it's filling up my error logs. DOes anyone know why it would report a 'Array sizes are inconsistent' error? Link to comment https://forums.phpfreaks.com/topic/227447-php-warning-array_multisort/#findComment-1173973 Share on other sites More sharing options...
BlueSkyIS Posted February 14, 2011 Share Posted February 14, 2011 var_dump($tmp_name) to see what's inside. Link to comment https://forums.phpfreaks.com/topic/227447-php-warning-array_multisort/#findComment-1174062 Share on other sites More sharing options...
undersun Posted February 15, 2011 Author Share Posted February 15, 2011 Thank you BlueSkyIS. Using var_dump($tmp_name) the output was: array(6) { [0]=> string(6) "Name A" [1]=> string(6) "Name B" [2]=> string(6) "Name C" [3]=> string(6) "Name D" [4]=> string(6) "Name E" [5]=> string(6) "Name F" } And using var_dump($details) the output was: (I added the line breaks) array(6) { [0]=> array(3) { [0]=> string(2) "62" [1]=> string(6) "Name A" [2]=> string(1) "1" } [1]=> array(3) { [0]=> string(2) "65" [1]=> string(6) "Name B" [2]=> string(1) "1" } [2]=> array(3) { [0]=> string(2) "56" [1]=> string(6) "Name C" [2]=> string(1) "1" } [3]=> array(3) { [0]=> string(2) "41" [1]=> string(6) "Name D" [2]=> string(1) "1" } [4]=> array(3) { [0]=> string(2) "64" [1]=> string(6) "Name E" [2]=> string(1) "0" } [5]=> array(3) { [0]=> string(2) "43" [1]=> string(6) "Name F" [2]=> string(1) "0" } } Is the "Array sizes are inconsistent" error thrown up because $details is a multi-dimensional array while $tmp_name isn't ?? Link to comment https://forums.phpfreaks.com/topic/227447-php-warning-array_multisort/#findComment-1174451 Share on other sites More sharing options...
BlueSkyIS Posted February 15, 2011 Share Posted February 15, 2011 i'm not sure about the error, but from googling, my impression is that each item in the arrays must be of the same size. for instance, some of the items in $details are string(2), while others are string(6) and string(1). Link to comment https://forums.phpfreaks.com/topic/227447-php-warning-array_multisort/#findComment-1174562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.