Welcome Guest, Not a member yet? Register   Sign In
in one foreach call second foreach!
#1

[eluser]daka[/eluser]
How is possible to call in foreach again foreach loop?
Hier is the deal:
I have photos table and I call it like this:
in controller:
Code:
$query_not_voted = "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'];
$data['myphotos'] = $this->db->query($query_not_voted);
if(IS_AJAX){
    $this->load->view('v_members_ajax', $data);
}else{
    $data['main_content'] = 'v_members';
    $this->load->view('includes/template', $data);
}
view:
Code:
foreach ($myphotos->result() as $myphoto){
echo $myphoto->p_small;
}
So now I need to call sql statment in that loop to get people that voted on that photo!
Hier is sql statment:
Code:
SELECT * FROM users WHERE u_id IN (SELECT u_id FROM p_votes WHERE p_id = 'every time in that loop different')

hier is my database:
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
in one foreach call second foreach! - by El Forum - 12-22-2010, 10:06 AM
in one foreach call second foreach! - by El Forum - 12-22-2010, 10:39 AM
in one foreach call second foreach! - by El Forum - 01-01-2011, 12:22 PM
in one foreach call second foreach! - by El Forum - 01-01-2011, 05:45 PM
in one foreach call second foreach! - by El Forum - 01-05-2011, 06:27 AM
in one foreach call second foreach! - by El Forum - 01-06-2011, 09:46 AM
in one foreach call second foreach! - by El Forum - 01-06-2011, 01:18 PM
in one foreach call second foreach! - by El Forum - 01-06-2011, 04:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB