Welcome Guest, Not a member yet? Register   Sign In
print_r() is not printing all contents?
#1

[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.


#2

[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.
#3

[eluser]whygod[/eluser]
@aken

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

#4

[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().
#5

[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
#6

[eluser]whygod[/eluser]
@TheFuzzy0ne

Thank you very much for your effort.





Theme © iAndrew 2016 - Forum software by © MyBB