SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Berlin
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    two sql tables with ID fields - how to change the name of one?

    I'm having two tables (kabul_fotos and kabul_fotos_kat), both have a field "id". I need to call the id field of only one table (kabul_fotos) to edit the right data set.

    --
    I calling the mySQL database:
    PHP Code:
    $result = @mysql_query("SELECT * FROM kabul_fotos, kabul_fotos_kat WHERE kabul_fotos.kat_id=kabul_fotos_kat.id Order by datum"); 
    [...]
    And want to edit the right set:
    PHP Code:
    <?="<a href='edit.php?id=$id'>Edit</a>"?>
    --

    The problem is, that it shows me the ID of the wrong table (kabul_fotos_kat)...

    Thus I tried to rename the ID field of one table like this:
    PHP Code:
    $result = @mysql_query("SELECT * kabul_fotos.id AS foto_id FROM kabul_fotos, kabul_fotos_kat WHERE kabul_fotos.kat_id=kabul_fotos_kat.id Order by datum"); 
    But it seems like this is not the right way... "kabul_fotos.id AS foto_id" dosn't work.

    Can someone help me - how do I do this?

    Thanks
    Fl÷zen
    Last edited by Floezen; May 20, 2003 at 14:39.

  2. #2
    SitePoint Addict Ramiro S's Avatar
    Join Date
    May 2003
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using an alias in the SELECT... like SELECT kabul_fotos.id AS TheRealID, * ....

    and then get the var like $ID=$row['TheRealID'];
    Quasar - Web Development - Free Avatars

  3. #3
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Berlin
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nop
    You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM table1, table2 WHERE table1.kat_id=table2.id'

    I wrote
    PHP Code:
    SELECT table1.id AS new_id, * FROM table1table2 WHERE table1.kat_id=table2.id 
    (In case there it is not correct: table1.id means field 'id' of the table 'table1' - that should be the way to identify the right 'id' field?! )

  4. #4
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    select table1.id as new_id, table2.* from table1, table2 where table1.kat_id=table2.id
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  5. #5
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Berlin
    Posts
    370
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, now it works

    PHP Code:
    select table1.id as new_idtable1.*, table2.* from table1table2 where table1.kat_id=table2.id 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •