how to show mysql search results with conditions [closed]

Problem :

this is my code

$getnews = mysqli_query($link, "SELECT t.idBerita, t.judul, t.headline, t.waktuAsal, t.lokasi, t.isiBerita, t.penulis, t.editor, t.sumber, t.waktuPengambilan, k.idKategori, g.namaKategori FROM tabelberita t, tabelketerangan k, tabelkategori g WHERE g.idKategori=k.idKategori ORDER BY waktuPengambilan DESC");

while($row = mysqli_fetch_array($getnews)){
    $id = $row['idBerita'];
    $judul = $row['judul'];
    $headline = $row['headline'];
    $waktuAsal = $row['waktuAsal'];
    $lokasi = $row['lokasi'];
    $isiBerita = $row['isiBerita'];
    $penulis = $row['penulis'];
    $editor = $row['editor'];
    $sumber = $row['sumber'];
    $waktuPengambilan = $row['waktuPengambilan'];
    $kategori = $row['kategori'];

    echo '<h3 style="text-align:center; font-size:20px">' .$judul. '<br></h3>';
    echo '<p style="text-align:center"><i>' .$headline. ' - <b>' .$sumber. '</b></i></p><br>';
    echo '<p style="font-size:11px">Oleh: ' .$penulis. '<br>';
    echo 'Editor : ' .$editor. '<br>';
    echo 'Kategori : ' .$kategori. '<br>';
    echo 'Waktu Pengambilan : ' .$waktuPengambilan. '</p><br>';
    echo '<div id="isi' .$id. '" style="display:none;">';
    echo '<p style="text-align:justify">&emsp;' .$isiBerita. '</p></div><br>';
    echo '<a href="javascript:showMore('.$id.')" id="more' .$id. '" style="display:block;"> Read More >></a>';
    echo '<a href="javascript:showLess('.$id.')" id="less' .$id. '" style="display:none;"> Read Less >></a>';
    echo '<br><br><br><br>';
    echo '';            

i want to show the results of the news with its category. the news and its category are in different table. but it's possible if some news don't have any category tagged to itself.

the problem is, with the above code, i could only show the news that have category tagged to itself, while news that don;t have any category tagged won't be shown. i want all of the news shown, with the news that don't have any category simply just show but with the empty category section.

how to query that?? thanks for any answers.

Solution :

You can use left outer join so that all the values from news irrespective of it having a category or not.

Mysql Tutorials

Mysql Howto..

When grouping a MYSQL query by month and year, how to order the data by month rather than alphabetical? Writing in PHP

How to get lowest value for 2 duplicate entries in PHP and MySQL

How to count how many times a table record has been updated [closed]

How to populate text input type based on select input type? [closed]

How to figure out size of Indexes in MySQL

MySql How to set a local variable in an update statement (Syntax?)

How to customize an error message in a MySQL stored function

How to implement MySQL::“LOAD DATA LOCAL INFILE” in PHP?

MYSQL How to get rows from highest rank to highest-range

How to check MySQL results during a 'while' table generation

How to include multiple COUNT per day in one query?

How to avoid race condition in MySQL

How to post and take data from MySQL for specific id from android app

How to use ON DUPLICATE KEY UPDATE in MySQL without a UNIQUE index or PRIMARY KEY?

How do you simulate memory shortage with MySQL?

Where can in insert mysql_real_escape_string in here? And how to prevent html from being entered? [closed]

How do I refactor this MySQL query?

MySQL xpath concatenation operator, how to add space?

MySQL How to obtain the MIN and MAX of the top 100 values in a table

How to build a “services” BD with prices

MySQL - how to get results back from a table, and the count of how many joined items there are in one query?

how to send parameters as input into mysql procedures?

How can I create a folder in php named as user register and link in mysql ?

How to place order by and group by in mysql query?

How to handle the different timezone in mysql?

How to delete a row from mysql via php

how to parse mysql error golang

How to check mysql db for an entry with less code

MYSQL to CSV - How to match column headings with selected columns

How can I determine which type of database is this?