CodeIgniter Forums
Why are the two first variables being left out in $x = $greet.' '.$row->sender .' '.$combined_message; - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Why are the two first variables being left out in $x = $greet.' '.$row->sender .' '.$combined_message; (/showthread.php?tid=61076)



Why are the two first variables being left out in $x = $greet.' '.$row->sender .' '.$combined_message; - El Forum - 09-12-2014

[eluser]thefatladysingsopera[/eluser]
I have the following code,

Code:
foreach ($query->result() as $row){

$greet = 'Bon Jour';
$x = $greet.' '.$row->sender  .' '.$combined_message;
}

but when i
Code:
echo x
,the values $greet.' '.$row->sender are being left out and only
Code:
$combined_message
although i have concatenated them.


Why are the two first variables being left out in $x = $greet.' '.$row->sender .' '.$combined_message; - El Forum - 09-12-2014

[eluser]Tim Brownlaw[/eluser]
So I am guessing that you would have tried...

Code:
foreach ($query->result() as $row){
  $greet = 'Bon Jour';
  $x = $greet.' '.$row->sender  .' '.$combined_message;
  echo $x; // Let's see what $x is!
}

Which resulted in $x only displaying what was in $combined_message.

So what happens if you try
Code:
foreach ($query->result() as $row){
  $greet = 'Bon Jour';
  $x = $greet.' '.$combined_message;
  echo $x; // Now Let's see what $x is!
}

If that works you would think Hmmm what is $row->sender doing, let's find out!
Code:
foreach ($query->result() as $row){
  $greet = 'Bon Jour';
  $x = $greet.' '.$combined_message;
  echo $x; // Now Let's see what $x is!
  var_dump($row->sender);
}

It's a process of examining everything... If something's not working... Pick it apart and actually see what you are getting...

So what do you get when you var_dump($row->sender);?