Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql not equal don't work
    text
    copied!<p>I have a SELECT statement that looks like this:</p> <pre><code> SELECT * FROM photos, p_votes WHERE p_votes.p_id = photos.p_id AND p_votes.u_id = 237 </code></pre> <p>And returns me results which I want, but I want just other way around: "I want all results that are not like above". So I was doing like this:</p> <pre><code> SELECT * FROM photos, p_votes WHERE p_votes.p_id != photos.p_id AND p_votes.u_id != 237 </code></pre> <p>but it doesn't return any results.</p> <p>Here is my insertion code:</p> <pre><code>$query = "UPDATE photos set p_up=p_up+1 where p_id=".$p_id; $result = $this-&gt;db-&gt;query($query); $this-&gt;load-&gt;helper('date'); $now = time(); $data_p_votes = array( 'p_id' =&gt; $p_id, 'u_id' =&gt; $this-&gt;session-&gt;userdata('u_id'), 'pv_ip' =&gt; $ip, 'pv_date' =&gt; unix_to_human($now, TRUE, 'eu') ); $query_p_votes = $this-&gt;db-&gt;insert('p_votes', $data_p_votes); </code></pre> <p>I just want to get photos that haven't been voted on by the user.</p> <p>Here is my database structure and some sample records:</p> <pre><code>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) default '0', `p_down` bigint(20) default '0', PRIMARY KEY (`p_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=260 ; INSERT INTO `photos` (`p_id`, `u_id`, `p_date`, `p_content`, `p_title`, `p_photo`, `p_small`, `p_thumb`, `p_up`, `p_down`) VALUES (255, 237, '2010-12-15 16:00:48', 'dock', 'dock', 'application/uploads/237/1292425240Dock.jpg', 'application/uploads/237/Jahorina-1292425240Dock.jpg', 'application/uploads/237/1292425240Dock_thumb.jpg', 1, 0), (254, 237, '2010-12-15 16:00:23', 'desert', 'desert', 'application/uploads/237/1292425214Desert Landscape.jpg', 'application/uploads/237/Jahorina-1292425214Desert Landscape.jpg', 'application/uploads/237/1292425214Desert Landscape_thumb.jpg', 1, 0) 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=235 ; INSERT INTO `p_votes` (`pv_id`, `u_id`, `p_id`, `pv_date`, `pv_ip`) VALUES (232, 237, 255, '2010-12-16 08:57:43', '85.146.204.228'), (233, 237, 259, '2010-12-16 09:10:27', '85.146.204.228'), (234, 237, 254, '2010-12-16 09:24:22', '85.146.204.228'); </code></pre> <p>Any suggestions?</p>
 

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