Jump to content

Recommended Posts

I have a problem with my array it gives me an offset error and have no idea how to fix it.. the idea is to find the lowest Group so that the user is assigned the lowest one thus hopefully keeping things as even as possible.... here is what i have:

 

<?php
$Get = mysql_query("SELECT ID FROM group WHERE Ended != '1' ORDER BY ID ASC")
	Or die(mysql_error());
	$State = array();
		While($row = mysql_fetch_assoc($Get)){
			$ID = $row['ID'];
			$Networth = 0;

			$SELECT = mysql_query("SELECT Houses+Money AS NetWorth
						FROM city WHERE SID='{$row['ID']}'")
							Or die(mysql_error());
	If(mysql_num_rows($SELECT)>0){
		While($row2 = mysql_fetch_assoc($SELECT)){
		$Networth = $Networth + $row2['NetWorth'];
			}
		}Else{
		$Networth = 0;
		}
	$City[] = $Networth; 
	unset($Networth);
	}

$temp = $City;  // make a temp array to sort, to preserve original array
sort($temp); // sort $temp to have lowest val first
$key = array_search($temp[0], $City); // search $array using first val in $temp, returning first key found
$val = $City[$key]; // get the value using the key found
$key = $key + 1;  // as the IDs are 1 / 2 / 3 or 4  .. key in array is 0 / 1 / 2 / 3  so + 1 makes them match
?>

 

 

The error recieved was:

 

Notice: Undefined offset: 0 in  council.php on line 87

 

Notice: Undefined offset: 0 in  council.php on line 88

 

 

Hope you can help out what is causing it!

 

 

Link to comment
https://forums.phpfreaks.com/topic/146125-solved-array-issues/
Share on other sites

The error is simple, you do not have an array with an index of 0, and in your code somewhere you are trying to access that.

 

Where I do not know, there are not 87 lines of code posted and you failed to highlight where that would have been, which is why you have not received an answer yet.

Link to comment
https://forums.phpfreaks.com/topic/146125-solved-array-issues/#findComment-767226
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.