Skip to content

Instantly share code, notes, and snippets.

@CodingTricksHub
Created June 22, 2017 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodingTricksHub/298fa302c63eca092182d1b0fb8db1f7 to your computer and use it in GitHub Desktop.
Save CodingTricksHub/298fa302c63eca092182d1b0fb8db1f7 to your computer and use it in GitHub Desktop.
<?php
$dbhost = "localhost";
$dbname = "checkboxlistview";
$dbuser = "root";
$dbpass = "";
if(isset($_GET["email"]))
{
$email=$_GET['email'];
$con=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname) or die('Database not connected');
$query1 = "select distinct fc.categoryId as 'id',c.categoryName,'true' as 'selected' FROM favouritecategories fc join categories c on c.id = fc.categoryId where fc.email = '$email'
union
select *,'false' as 'selected' from categories c where Id not in (SELECT distinct fc.categoryId FROM favouritecategories fc
join categories c on c.id = fc.categoryId where fc.email = '$email')
order by categoryName
";
$result1 = mysqli_query($con, $query1) or die("Error in Selecting " . mysqli_error($connection));
$temparray = array();
while($row =mysqli_fetch_assoc($result1))
{
$temparray[] = $row;
}
echo json_encode($temparray);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment