PDA

View Full Version : Sql Problems, Same Field Names In Multiple Mysql Tables?


NerdArmy
12-05-2011, 07:52 PM
I have a keyword search that searches multiple DB tables for thumbnail images using UNION ALL. I have two pages, results.php, and view.php. My goal is to able to click a thumbnail image on results.php and be directed to a larger version of that same image on view.php. The problem is each image in all my tables uses the field name "id" so when I click a thumbnail on results.php I get two different images with the same id from different tables. I tried changing the id's to different names, but when it was time to pass url parameters I can only choose 1 value. (if you can choose more than 1 I don't know how). So my question is why are my id's from different tables being grouped together, and how can I change this?


Image Results Page (which works perfect):

SELECT *
FROM table1
WHERE keyword LIKE %colname% OR id LIKE %colname%
UNION ALL
SELECT *
FROM table2
WHERE keyword LIKE %colname% OR id LIKE %colname%



View Image Page (having problems here):

SELECT *
FROM table1
WHERE id = colname
UNION ALL
FROM table2
WHERE id = colname

edbr
12-05-2011, 11:59 PM
how is the link passed from results page to view.php?

NerdArmy
12-06-2011, 12:09 AM
url parameters: viewtest.php?id=<?php echo $row_Recordset1['id']; ?>

edbr
12-06-2011, 01:36 AM
ok first check what is being passed
echo $_GET['id']:
im assuming that is a unique value, i doubt (guessing here) that you need to select from both tables then in view.php.
so select from that table that supplies the large size link. if this is over simplifying the problem maybe try a join based on two unique matching values.
It a little hard to say with out knowing the whole structure

are table1.id the same as table2.id ?

NerdArmy
12-06-2011, 02:21 AM
yes they're the exact same.

edbr
12-06-2011, 02:31 AM
$where=$_GET['id'];


SELECT * FROM table1 JOIN table2 ON table1.id=table2.id where table1 = $where;

should be ok then image src ="images/ <?echo <?php echo $row_Recordset1['link']; ?>

or what ever the link field is called . tell me if im not getting the structure thouh