How to check id in table A and B

hi everyone please help, actually i have two table A and B.
and i have created two pages for A and B. there are 50-50 product available in A and B.
after that i have created a page for view individual product using get method with id, like
“select * from A where id=‘$id’;”

its working fine but after that when i go to page B for table B please suggest have to create second view page for table B? like “select * from B where id=‘$id’;”
or can i use any query for both table in single page(view.php)

You can use single view.php If you’ll pass product type as GET-parameter to it:

view.php?product=a&id=5
view.php?product=b&id=5

In this case you’ll be able to check what table to use in view.php:

$productType = $_GET['product'];
$id = (int)$_GET['id'];

switch($productType){
    case 'a': $table = "TableA"; break;
    case 'b': $table = "TableB"; break;
}

$sql = "SELECT FROM `{$table}` WHERE id = '{$id}'";

hello megazoid,

i am just trying select * from a where id=‘$id’ union select * from b where id=‘$id’
but not working…

Define “not working”. Is it showing you only entries from table A? Is it showing you nothing? Is it giving you a Blank Screen of Syntax Error?

Hi its working fine now actually column was mismatch in both table (means 8 column in A and 10 column in B). Now its fine…thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.