undefined offset: 4 - where!!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

undefined offset: 4 - where!!!!

Post by IGGt »

This is really annoying now. I have the following code, but every time I run it it says:
[text]
"Notice: Undefined offset: 4 in C:\wamp\www\tsLive\mfQuery3.php on line 41"[/text]
and also line 63 and line 78 (marked below)

But I can't see where it is getting the offset of 4 from, as there are only 3 queries (0,1,2), and 4 customers (0,1,2,3).

Code: Select all


<?php 

// Query3 - LIVE 

//queries
$q1 = "SELECT COUNT(*) AS 'count' FROM jobs WHERE LEFT(`starttime`,10) = CURDATE() AND `customerid` =";

$q2 = "SELECT COUNT(*) AS 'closed' FROM jobs WHERE LEFT(`starttime`,10) = CURDATE() AND `closed` IS NOT NULL AND `customerid` =";

$q3 = "SELECT COUNT(*) AS 'open' FROM jobs WHERE LEFT(`starttime`,10) = CURDATE() AND `closed` IS NULL AND `customerid` =";
	
//mfO query_array
$mfOquery_array = array();
$mfOquery_array[] = array(	'query1' => $q1,
						'query2' => $q2,
						'query3' => $q3 
					);													
							
//list of Customers
$Oarray[] = array(	'name' => "Cust1",
					'id' => "117");
$Oarray[] = array(	'name' => "Cust2",
					'id' => "404");
$Oarray[] = array(	'name' => "Cust3",
					'id' => "255");
$Oarray[] = array(	'name' => "Cust4",
					'id' => "466");	
							
//mf connections
$mfO_array = 	 $connections_array[7];
				
//									        											
	$con = mysql_connect($mfO_array['server'], $mfO_array['user'], $mfO_array['password']);
		mysql_select_db($mfO_array['default'], $con);
       
        	foreach($mfOquery_array as $Oquery) {

	        	for($b = 0; $b <sizeof($Oarray); $b++) {
		        	
// QUERY 1	        	
		        	$mfOquery = $Oquery['query1'].$Oarray[$b]['id']; // --> this is line 41	
	       				$mfOres1 = mysql_query($mfOquery);
        	    	
        				if ( !$mfOres1 ) { 	$error = mysql_error();
        					print "<table style=\"width:98%; border: 5px solid black; align: center; text-align: center; font-size:14px; color:black; ><tr><th>ERROR HAS OCCURRED</th></tr>\"";
        					print "<tr><td>".$error."</td></tr></table>";
    					}
    					
    					while($mfOrow1 = mysql_fetch_assoc($mfOres1)) {
	                		$OtotalJobs[$db['database']] = $mfOrow1;
	                		$Oarray[$b]['count'] = $mfOrow1['count'];
	               						}
               					
// QUERY 2
		        	$mfOquery = $Oquery['query2'].$Oarray[$b]['id']; // --> this is line 63	
	       				$mfOres2 = mysql_query($mfOquery);
        	    	
        				if ( !$mfOres2 ) { 	$error = mysql_error();
        					print "<table style=\"width:98%; border: 5px solid black; align: center; text-align: center; font-size:14px; color:black; ><tr><th>ERROR HAS OCCURRED</th></tr>\"";
        					print "<tr><td>".$error."</td></tr></table>";
    					}
    					
    					while($mfOrow2 = mysql_fetch_assoc($mfOres2)) {
	                		$OcloseJobs[$db['database']] = $mfOrow2;
	                		$Oarray[$a]['closed'] = $mfOrow1['closed'];
	               						}         							

	               						
// QUERY 3
		        	$mfOquery = $Oquery['query3'].$Oarray[$b]['id']; // --> this is line 78	
	       				$mfOres3 = mysql_query($mfOquery);
        	    	
        				if ( !$mfOres3 ) { 	$error = mysql_error();
        					print "<table style=\"width:98%; border: 5px solid black; align: center; text-align: center; font-size:14px; color:black; ><tr><th>ERROR HAS OCCURRED</th></tr>\"";
        					print "<tr><td>".$error."</td></tr></table>";
    					}
    					
    					while($mfOrow3 = mysql_fetch_assoc($mfOres3)) {
	                		$OopenJobs[$db['database']] = $mfOrow3;
	                		$Oarray[$a]['open'] = $mfOrow3['open'];
	               						}    
               						          
        						}
    						}     							        							
	mysql_close($con);	
															
?>								
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

Re: undefined offset: 4 - where!!!!

Post by IGGt »

Well I have narrowed it down.

By removing everything and adding it back in a line at a time, it is fine till I get to Query2 > line 72

Code: Select all

$Oarray[$a]['closed'] = $mfOrow2['closed'];
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: undefined offset: 4 - where!!!!

Post by Celauran »

I don't see $a defined anywhere. That's where I'd look next.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: undefined offset: 4 - where!!!!

Post by mikosiko »

No related with your error... just curiosity.... is any reason why you wrote your code in that way? (maybe is an array assignment proof of concepts?)... curious because you can do all of that using just one SELECT and most likely with only one loop... as I said... maybe is just an array's usage test.
Post Reply