Fred007 Fred007 - 3 months ago 9
MySQL Question

Php-Mysql choosing rows from database based on Domain column

I made my page to show different rows from database based on different site I click on (for example when I click on 123 in my menu, it will show different table rows than in 321 menu, everythink on same site).

It works like this:

$id_dom=$_GET['id_dom'];
$query = mysql_query("SELECT * FROM summary WHERE Domain='$id_dom'");


So when I go to page: test.com/db.php?id_dom=123 , it will show different table than in test.com/db.php?id_dom=321 .

But now I need to make one page (.php?id_dom=ALL) to display ALL table rows (from 123 and 321 column).

I know I need to use "if" function, but everytime i tried to make it, it didnt work.

Answer

You should use two different select

if ($id_dom =='ALL')  {
    $query = mysql_query("SELECT * FROM summary ");
} else {
    $query = mysql_query("SELECT * FROM summary WHERE Domain='$id_dom'");
}