#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    7
    Rep Power
    0
    I have two separate tables in my database - one with information and one with photos. I would like to link the two of these tables together. So when you go to an information page there is a small link that has a link to a photo for that fish. And vise versa when you go to the photos page.

    The way I am going to have to link the tables together is by their scientific name. Because that is the only thing that they have in common. I tired something like this:

    $result16 = mysql_query("SELECT * FROM photos WHERE $id=id",$db);
    $result17 = mysql_query("SELECT * FROM info WHERE $result16=scientific_name",$db);
    while ($myrow = mysql_fetch_array($result17)) {
    printf("More information about <a href=$info_php?id=%s&author=%s><b>%s</b></a>?", $myrow["id"], $myrow["author_id"], $myrow["common_name"]);
    }

    I keep getting a 0 result when I do this.

    I only want the link to show up if there is information about the fish in the other table. Also, the fields that I am tiring to link have multiple words because they are scientific names.

    Does anyone know a better way for me to do this?

    Off the subject - In my script I used "SELECT * FROM table". Does it kill a server if you use this A LOT. Sometimes when the script is loading it is being used 6-7 times.

    ------------------


    [This message has been edited by fishindex (edited June 20, 2000).]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Posts
    114
    Rep Power
    16
    I'm not sure I got it completely, but it looks like you need some sort of join:

    select * from info, photos where info.id=photo.id;
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    7
    Rep Power
    0
    I probably wasn't too clear. I want to match table1 to table2 if any row in column1 is the same in the both of the tables. BUT in column1 all the records are something like "Foo foo." I think I can't get it to work because there are two words.

    Would I use the join thing for something like this?

    ------------------
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    3
    Rep Power
    0
    hello fishindex..

    Please give full details of table with fields so that I can help U well.

    vijay
  8. #5
  9. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    select photo.picture as picture, info.scientificname as s_name, info.author as author, info.commonname as c_name from photo,info where photo.scientificname = info.scientificname;

    I think that will work.

    ---John Holmes
    ---www.SepodatiCreations.com

Similar Threads

  1. Large tables or many small tables?
    By Tassadar356 in forum MySQL Help
    Replies: 4
    Last Post: February 8th, 2004, 01:07 PM
  2. tables get corrupted
    By 90coders in forum MySQL Help
    Replies: 1
    Last Post: December 5th, 2003, 05:23 AM
  3. Replies: 0
    Last Post: October 15th, 2003, 08:02 PM
  4. Synchronizing 2 tables with different field structure
    By nickcwj in forum Database Management
    Replies: 0
    Last Post: October 15th, 2003, 07:55 PM
  5. 3 tables overlapping help (CSS / Javascript)
    By static07 in forum JavaScript Development
    Replies: 2
    Last Post: September 4th, 2003, 06:40 AM

IMN logo majestic logo threadwatch logo seochat tools logo