• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
basic php problem.

I am not sure how this is supposed to work? $results is an array that gets loaded with a few records. I have looked for $row to be populated somewhere else in the code but it is not. My debugger runs down to the $image_filename. But $image_filename is null according to the debugger. I think that it should be the $row->URL_field, which is a string. 

PHP Code:
$results $this->ci->db->get($this->table_name)->result();

$thumbnail_url = !empty($this->thumbnail_path) ? $this->thumbnail_path $this->image_path;
  $final_results = array();
$results as $num => $row)
  $image_filename $row->{$this->url_field};  //this is the field that should be populated with the URL string
if (empty($image_filename)) {

Any idea why this is failing to get the string in the URL field? It seems to work normally, except if there is only one row.  What is the first row? $row or $row+1?
proof that an old dog can learn new tricks


Have you tried dumping the variable after you get the results (var_dump)?

Thanks Rocs!.  I haven't done a var_dump (I pretty much really on the debugger). Here us one possibility:

foreach($results as $num => $row)  What is $row? is that the number of rows? Isn't an array indexed from zero?

So if $row returns 3 (in this case), $row[3] is pointing at a row that doesn't exist. I have never seen that foreach value ($row) used as an index. I guess the question is " in PHP, are array indexes zero based?". BTW I am using PHP 7.0. I see this note about foreach. What does it mean? 

Quote:As [i]foreach[/i] relies on the internal array pointer in PHP 5, changing it within the loop may lead to unexpected behavior.
In PHP 7, [i]foreach[/i] does not use the internal array pointer.
I guess the question is what is $row assigned by foreach($results as $num => $row) ? Is it  a pointer like it would be in "C" as in &row, Or is it an integer? I am assuming that it will be an int, but I really don't know. The next line in the code it is used like this 

$image_filename = $row->{$this->url_field};

Which makes me thinks that it is a pointer. Perhaps it should be used like this? 
$current=$row(count) and then
$image_filename $row[current].url_field};
proof that an old dog can learn new tricks

Did you try

PHP Code:
$image_filename $row->url_field
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

This is not my code but I can give it a try. I don't even know why he uses this-> so much. My understanding is that php  under apache uses a multiprocess paradigm, not multithreading, thus a variable used by one  user shouldn't bleed to another user. Right?
proof that an old dog can learn new tricks

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.