CodeIgniter Forums
print_r() is not printing all contents? - 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: print_r() is not printing all contents? (/showthread.php?tid=57633)



print_r() is not printing all contents? - El Forum - 03-28-2013

[eluser]whygod[/eluser]
Hi guys

I'm not sure where the problem exactly is.
controller: front.php
Code:
function index() {
  //$this->data['header'] = $this->load->view('template/header', $this->data, TRUE);
  $this->data['follow_links'] = $this->folio_model->get_follow_links();
  $this->data['footer'] = $this->folio_model->read_footer_text();
  $this->load->view('template/master', $this->data);  
}

model: folio_model
Code:
function get_follow_links()
{
  //fetch content of followlinks table and store them into array.
  $query = $this->db->select('facebook', 'twitter', 'rss', 'youtube', 'contact')
         ->where('idfollow', 1)
        ->get('followlinks');        

  if($query->num_rows() > 0)
  {
   return $query->result_array();
  }
}

view: master.php
Code:
<?php
  echo '<br>';
  echo '<pre>';
   print_r($follow_links);
  echo '</pre>';
  echo '<br>';    
?&gt;

The problem is it only print only one value,
Code:
Array
(
    [0] => Array
        (
            [facebook] => http://facebook.com
        )

)

But the table followlinks has more than values.
It has facebook url, twitter url, rss url, youtube url etc...

Anyone would like to give shed to this?
Thank you very much in advanced.





print_r() is not printing all contents? - El Forum - 03-29-2013

[eluser]Aken[/eluser]
All of your select items should be put in the first parameter, as a string or an array. select() does not accept unlimited parameters.

Also, if you're only selecting one row from your DB, use row() or row_array(), not result/result_array.


print_r() is not printing all contents? - El Forum - 03-29-2013

[eluser]whygod[/eluser]
@aken

thanks, but can you show me sample codes of SELECT?




print_r() is not printing all contents? - El Forum - 03-29-2013

[eluser]TheFuzzy0ne[/eluser]
$this->select() only accepts a single string, or an array of strings. So this:
Code:
$query = $this->db->select('facebook', 'twitter', 'rss', 'youtube', 'contact')

becomes this:
Code:
$query = $this->db->select('facebook, twitter, rss, youtube, contact') // One string

or this:
Code:
$query = $this->db->select(array(
    'facebook',
    'twitter',
    'rss',
    'youtube',
    'contact',
))

Also, if you're only expecting a single row to be returned, consider using row_array() instead of result_array().


print_r() is not printing all contents? - El Forum - 03-29-2013

[eluser]Aken[/eluser]
[quote author="whygod" date="1364543450"]@aken

thanks, but can you show me sample codes of SELECT?

[/quote]

The user guide comes in handy for these kinds of things. Wink


print_r() is not printing all contents? - El Forum - 03-29-2013

[eluser]whygod[/eluser]
@TheFuzzy0ne

Thank you very much for your effort.