Note that there are some explanatory texts on larger screens.

plurals
  1. POcodeigniter pass data from view to model and retrieve info
    primarykey
    data
    text
    <p>Here is the thing: I have controller that retrieve data from database and pass info to view. In the view I have a loop like this:</p> <pre><code>foreach ($myphotos-&gt;result() as $myphoto){ echo $myphoto-&gt;p_id } </code></pre> <p>But in that loop I need to pick up $myphoto->p_id and ask database to retrieve me users with this p_id.</p> <pre><code>SELECT * FROM users WHERE u_id IN (SELECT u_id FROM p_votes WHERE p_id = 268); </code></pre> <p>and in:</p> <pre><code>foreach ($myphotos-&gt;result() as $myphoto){ echo $myphoto-&gt;p_id $this-&gt;load-&gt;model('m_member'); $users_voted = $this-&gt;m_member-&gt;getUsersVotedOnImage($myphoto-&gt;p_id); foreach ($users_voted-&gt;result() as $users){ echo '&lt;div id="voterfooter"&gt;voted:&lt;a href="$users-&gt;i_id"&gt;'.$users-&gt;name.&lt;/a&gt; } } </code></pre> <p>Ok that was one option that I come up, but there is also another option, but select statement is so complicated!</p> <p>here is how: I already have this one:</p> <pre><code>SELECT * FROM photos WHERE p_id NOT IN (SELECT distinct p_id FROM p_votes where u_id = ".$this-&gt;session-&gt;userdata('u_id').") LIMIT ".$segment_url.", ".$config['per_page']; </code></pre> <p>But how to pick up also from users people that voted on that picture and print it in view?</p> <p>Here is database scheme:</p> <pre><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 ; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload