• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 52
  • Last Modified:

print_r affects the data?

OK I think this is the weirdest yet.  To me, anyway.

If I leave in lines 3,4,5 the code appears to work (displays the array, shows no error).

If I comment out those lines, it fails
Severity: Notice

Message: Undefined offset: 0

Filename: models/Week_fixtures_model.php

Line Number: 490

if ( $query->num_rows() == 1)
		{
			echo "<PRE>";
			print_r($query->result_array());
			echo "</PRE>";
			$arr_venue_info['name'] = $query->result_array[0]['name'];
			$arr_venue_info['mapref'] = $query->result_array[0]['mapref'];
			return $arr_venue_info;	
		}
		else // no ground found.
		{
			$arr_venue_info['name'] = $venue;
			$arr_venue_info['mapref'] = 'No map';
			return $arr_venue_info;	
		}

Open in new window


Can anyone shed any light on this please?  I'm using CodeIgniter if that is relevant.
0
colinspurs
Asked:
colinspurs
  • 2
1 Solution
 
Dave BaldwinFixer of ProblemsCommented:
result_array() Likely actually causes the data to be fetched and without it, you don't have any data.  'printr()' just prints the results.   I don't find any such command in PHP database drivers.  Is that a CodeIgniter command?
0
 
colinspursAuthor Commented:
Ah OK, so what I need is
if ( $query->num_rows() == 1)
		{
			$my_array = $query->result_array();
			$arr_venue_info['name'] = $my_array[0]['name'];
			$arr_venue_info['mapref'] = $my_array[0]['mapref'];
			return $arr_venue_info;	
		}
		else // no ground found.
		{
			$arr_venue_info['name'] = $venue;
			$arr_venue_info['mapref'] = 'No map';
			return $arr_venue_info;	
		}

Open in new window

0
 
colinspursAuthor Commented:
Thanks Dave.  I need a holiday!
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now