SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how can i do this mysql query .. plz !

    hi ...

    i have 5 table, and am query the data like this :
    PHP Code:
    $Q mysql_query("select * from 
                    advert Ads , 
                    car_zoon As Zoon ,
                    car_type as Type , 
                    car_model As Model ,
                    car_opt As Opti
                
                    where 
                    Ads.ad_stat = 'wait'  and 
                    Zoon.zid = Ads.car_zoon and 
                    Type.car_id = Ads.car_type and 
                    Model.mid = Ads.car_model And 
                    Opti.ad_id = Ads.id limit 
    $offset,$Limit
                    "
    ) OR Die("Admin Error func New Ads :<br>".mysql_error()); 
    it`s work fine as i need , but now i must get some more info from another table name 'acces' , with term ' acces_stat = 'wait' !

    how can i do this, coz it didn`t work with above code ?


    thx ..

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try changing this:
    PHP Code:
    Ads.ad_stat 'wait' 
    to this:
    PHP Code:
    Ads.ad_stat LIKE 'wait' 

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    joel, without a wildcard character in the LIKE expression, those two statements are equivalent

    richi, i understand you want "more info from another table name 'acces'" so i think all you need to do is join it to the other 5 tables

    perhaps something like
    Code:
    select * 
      from advert       Ads
         , car_zoon  As Zoon
         , car_type  as Type
         , car_model As Model
         , car_opt   As Opti 
         , access 
     where Ads.ad_stat = 'wait' 
       and access.acces_stat = 'wait'  
       and access.aid = Ads.access_id 
       and Zoon.zid = Ads.car_zoon
       and Type.car_id = Ads.car_type
       and Model.mid = Ads.car_model
       and Opti.ad_id = Ads.id 
    limit $offset,$Limit
    notice how i had to guess the join condition access.aid = Ads.access_id
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    r937 :

    yes that what i need ... but the acces table has no relation with any table , i mean it`s stand alone ..
    coz my dumb claint in the end he remember he need accessories also

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    no relation to the other tables? hmmm...

    okay, pull out that join condition, and keep the and access.acces_stat = 'wait' condition

    this will cross-join this one row with the other tables

    however, you should have at least one column from acces in the SELECT list, otherwise there's no point adding the acces table to the query
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    grrrrrrrrrrr


    i had redesign the db coz of this ************ client

    now i had this problem, it`s found nothing :

    PHP Code:
        $Q = @mysql_query("select * from 
        advert Ads , 
        car_zoon As Zoon ,
        car_type as Type , 
        car_model As Model ,
        car_opt As Opti
        [COLOR=red], other_ads as Other[/COLOR]
        
        where 
        
        Ads.user = '
    $User_ID'  and 
        Zoon.zid = Ads.car_zoon and 
        Type.car_id = Ads.car_type and 
        Model.mid = Ads.car_model And 
        Opti.ad_id = Ads.id   
        and [COLOR=red]Other.ad_id = Ads.id[/COLOR]

        
        order by Ads.id DESC limit 
    $offset,$Limit
        "
    ) OR Die(mysql_error()); 
    there are table with name advert :

    Code:
    Field Type Attributes Null Default Extra 
    id  int(7)   No    auto_increment  
    user  int(7)   No  0    
    car_zoon  int(7)   No  0    
    car_type  int(7)   No  0    
    car_model  int(7)   No  0    
    date  varchar(15)   No      
    ad_stat  varchar(20)   No      
    on_start  char(1)   No      
    view  varchar(5)   No  0

    and table other_ads

    Code:
    Field Type Attributes Null Default Extra 
    o_id  int(7)   No    auto_increment  
    ad_id  int(7)   No  0    
    o_type  varchar(30)   No      
    o_title  varchar(50)   No      
    o_ad  text   No

    what the wrong here plz ?!




    thx.

  7. #7
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok found it !


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
  •