SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with identifying COLUMN NAME

    Hi

    I have 2 tables one for user and 1 for his ADs. He has his SKILLS in the user table. But he also has skills for the ADs. and the column names for the skills are same in both the table. like READING , WRITING, KICKING, SWIMMING available in both the tables. (its a requirement) and unfortunately there column names are same in both the tables.

    Now i have a SQL like...

    global $dbconn;

    $qyery = "select * from user u, ads a where a.userno=1 and a.id=1221 and aduserno = u.userno";

    $res= @mysql_query($query,$dbconn);

    $resarray = @mysql_fetch_array($res);

    now if i want to echo the value of u.reading and a.reading how can i access them using

    $ad_reading = $resarray['a.reading'];
    $user_reading = $resarray['u.reading'];

    it gives error for using a. or u. in $resarray.....

    pzl help

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $qyery "SELECT *, u.reading as ureading, a.reading as areading FROM user AS u, ads AS a WHERE a.userno=1 AND a.id=1221 AND aduserno = u.userno";

    $res= @mysql_query($query,$dbconn);

    $resarray = @mysql_fetch_array($res);

    $ad_reading $resarray['areading'];
    $user_reading $resarray['areading']; 
    How about this?
    -- Jelena --

  3. #3
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems good, and i m gonna use this. I want one more thing here. I want to get all fields from ADS and few Fields from USER. How to do that ????

    like is it possible

    select user.*, ads.reading, ads.writing, ads.speaking ads.etc from user, ads

    is it ok ?

  4. #4
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes, it is ok, but be careful if some of the column names from two tables are the same. It so, make sure to use AS.
    -- Jelena --

  5. #5
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi i got the solution i can do that. like

    select ads.*,user.email from ads,user where ads.userno = user.userno


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
  •