Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803

    Unanswered: How to insert a row of data using a condition

    Hello everyone.

    I have sort of an issue that I have stumbled on and don't know how to resolve it. Maybe someone can point me in the right direction here.

    I have 3 tables like so:

    Code:
    dspatch
    dispatch_Id
    
    narrative
    narrative_id
    dispatch_id
    
    narrative_Photo
    photo_id
    narrative_id
    path
    size

    Here is some sample data from the narrative_Photo tale I am having a problem with:

    Code:
    photo_id     narrative_id     path          size
    1            1                /docs/1.jpg     1kb
    Here is the sql I am using so far:
    Code:
    SELECT
    `narrative_Photo`.`narrative_Photo_Id`,
    `narrative_Photo`.`path`
    FROM
    `narrative_Photo`
    Inner Join `narrative` ON `narrative`.`narrative_Id` = `narrative_Photo`.`narrative_Id`
    Inner Join `dispatch` ON `dispatch`.`dispatch_Id` = `narrative`.`dispatch_Id`
    WHERE
    `dispatch`.`incident_Number_Id` =  '1'
    I need a second condition for the "dispatch_Id". My php code needs to first match the row where the dispatch_Id = something then insert the rest of the data.

    I could get around this whole issue if I just put the PK from the incident table as the FK in the narrative_Photo table, effectively bypassing the incident table but that is not correct. I hope I am making myself clear.

    Can someone please give me a hand?

    Thanks

  2. #2
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    I'm somewhat confused.
    First off, what is the DDL for your tables? I can guess integers and varchars but it may not be the case.
    Secondly, i'm not sure i follow the question.

    1) Are you trying to insert data?
    2) If yes, what data are you inserting?
    3) Are you attempting to insert "cross-table" i.e. into more than 1 table at a time.

    From what I can see from your post you are doing a select statement, which doesn't make sense in relevance to the question title. What are you inserting and where?

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by fjm1967
    I could get around this whole issue if I just put the PK from the incident table as the FK in the narrative_Photo table, effectively bypassing the incident table but that is not correct. I hope I am making myself clear.
    sorry, you aren't

    incident table? what incident table?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Mar 2007
    Location
    010101010110100
    Posts
    803
    Thank you both for your replies. I am thinking that this is more of a php session question than an sql question.

    With the sql, I can generate the insert statement that I need but in php it is different.

    I think I really need to understand what is happening first with the php. I'll post back if I still need help..

    Thank you!!

Posting Permissions

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