Jump to content

[SOLVED] Query help


tgavin

Recommended Posts

This problem I'm having is a result of having to update a table and query. If needed, check the original topic: http://www.phpfreaks.com/forums/index.php/topic,107845.0.html for background.

 

I'm displaying a series of checkboxes, and ticking the ones the subscriber belongs to. This was working just fine, until I updated the table with a new column: subscribed.

 

Here's the current query:

$query = "SELECT n.ln_id, n.ln_name, s.ls_list_id FROM {$database}.list_names n LEFT JOIN {$database}.list_subscribers s ON n.ln_id = s.ls_list_id AND s.ls_sub_id = '".$id."'";

 

So, I need for this query to now

1. Show all checkboxes

2. tick off the ones in which subscribed=1

 

If I just put WHERE subscribed=1 into the query, then it only shows those checkboxes on the page, not all of them.

 

Here's the table

CREATE TABLE `list_subscribers` (
  `ls_list_id` int(10) unsigned NOT NULL default '0',
  `ls_sub_id` int(10) unsigned NOT NULL default '0',
  `email` varchar(60) NOT NULL default '',
  `news_id` int(10) unsigned NOT NULL default '0',
  `subscribed` char(1) NOT NULL default '0',
  PRIMARY KEY  (`ls_list_id`,`ls_sub_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Link to comment
https://forums.phpfreaks.com/topic/42549-solved-query-help/
Share on other sites

Why not run 2 separate queries? One to get the check boxes ticked and one to get where the check boxes aren't ticked?

 

IE: use WHERE subscribed =1 and start that into $query1 and WHERE subscribed = 0  and store that into $query2.

 

If for some reason that is not a viable option, well post some code.

 

--FrosT

Link to comment
https://forums.phpfreaks.com/topic/42549-solved-query-help/#findComment-206670
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.