Welcome Guest, Not a member yet? Register   Sign In
codeigniter pass data from view to model and retirve info
#1

[eluser]daka[/eluser]
Hier is the thing: I have controller that retrive data from database and pass info to view. In the view I have a loop like this:
Code:
foreach ($myphotos->result() as $myphoto){
echo $myphoto->p_id
}
But in that loop I need to pick up $myphoto->p_id and ask database to retrive me users with this p_id.
Code:
SELECT * FROM users WHERE u_id IN (SELECT u_id FROM p_votes WHERE p_id = 268);
and in:
Code:
foreach ($myphotos->result() as $myphoto){
echo $myphoto->p_id
$this->load->model('m_member');
$users_voted = $this->m_member->getUsersVotedOnImage($myphoto->p_id);
foreach ($users_voted->result() as $users){
echo '<div id="voterfooter">voted:<aaa href="$users->i_id">'.$users->name.</a>
}
}
Ok that was one option that I come up, but there is also other option, but select statment is so complicated!

hier is how: I already have this one:
Code:
SELECT * FROM photos WHERE p_id NOT IN (SELECT distinct p_id FROM p_votes where u_id = ".$this->session->userdata('u_id').") LIMIT ".$segment_url.", ".$config['per_page'];


Hier is the thing: I have controller that retrive data from database and pass info to view. In the view I have a loop like this:

foreach ($myphotos->result() as $myphoto){
echo $myphoto->p_id
}

But in that loop I need to pick up $myphoto->p_id and ask database to retrive me users with this p_id.

SELECT * FROM users WHERE u_id IN (SELECT u_id FROM p_votes WHERE p_id = 268);

and in:

foreach ($myphotos->result() as $myphoto){
echo $myphoto->p_id
$this->load->model('m_member');
$users_voted = $this->m_member->getUsersVotedOnImage($myphoto->p_id);
foreach ($users_voted->result() as $users){
echo '<div id="voterfooter">voted:<aaaa href="$users->i_id">'.$users->name.</a>
}
}

Ok that was one option that I come up, but there is also other option, but select statment is so complicated!

hier is how: I already have this one:

SELECT * FROM photos WHERE p_id NOT IN (SELECT distinct p_id FROM p_votes where u_id = ".$this->session->userdata('u_id').") LIMIT ".$segment_url.", ".$config['per_page'];

But how to pick up also from users people that voted on that picture and print it in view?

Hier is database scheme:
Code:
CREATE TABLE IF NOT EXISTS `users` (
  `u_id` int(10) unsigned NOT NULL auto_increment,
  `fb_id` varchar(255),
  `fb_url` varchar(255),
  `email` varchar(100),
  `username` varchar(100),
  `name` varchar(100),
  `lastname` varchar(100),
  `mini_pic_fb` varchar(255),
  `mini_pic` varchar(255),
  `country` varchar(100),
  `place` varchar(100),
  `address` varchar(100),
  `nr` int(10),
  `postcode` varchar(10),
  `pass` varchar(35),
  `active` varchar(35),
  `activation_code` varchar(42),
  PRIMARY KEY  (`u_id`),
  UNIQUE KEY `email` (`email`),
  UNIQUE KEY `username` (`username`),
  UNIQUE KEY `fb_id` (`fb_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=229 ;


CREATE TABLE IF NOT EXISTS `photos` (
  `p_id` bigint(20) unsigned NOT NULL auto_increment,
  `u_id` bigint(20) unsigned NOT NULL default '0',
  `p_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `p_content` longtext NOT NULL,
  `p_title` text NOT NULL,
  `p_photo` text NOT NULL,
  `p_small` text NOT NULL,
  `p_thumb` text NOT NULL,
  `p_up` bigint(20),
  `p_down` bigint(20),
  PRIMARY KEY  (`p_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=229 ;

CREATE TABLE IF NOT EXISTS `p_votes` (
  `pv_id` bigint(20) unsigned NOT NULL auto_increment,
  `u_id` bigint(20) unsigned NOT NULL,
  `p_id` bigint(20) unsigned NOT NULL,
  `pv_date` datetime NOT NULL default '0000-00-00 00:00:00',
  `pv_ip` varchar(200) NOT NULL,
  PRIMARY KEY  (`pv_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=229 ;


Messages In This Thread
codeigniter pass data from view to model and retirve info - by El Forum - 12-22-2010, 06:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB