Another 2 tables query problem

Results 1 to 2 of 2

Thread: Another 2 tables query problem

  1. #1
    Join Date
    Dec 1969

    Default Another 2 tables query problem

    I have 2 tables tblTopics and tblImages. Those 2 tables are related where tblImages have FK(TopID) of PK(ID) from tblTopics. Since the user can upload image before saving the topics record, so I assign the value -1 in field TopID. After user save the topics records and I got the Topics ID, I want to update the value of the TopID in tblImages as the value of ID. So I give this query:<BR><BR>sqlImgUpd = "UPDATE Image SET TopID = " & Clng(TopID)<BR>sqlImgUpd = sqlImgUpd & " WHERE TopID = -1;"<BR><BR>My problem is, My web page allowed user to upload more than 1 Topics and each topic they can upload the image. So, let say user upload 2 images and input 2 topics. After I retrieve the topics1 ID value (i.e. 20) then I apply sqlImgUpd above, both the image TopID value become 20. <BR><BR>What I tend to do is only one first image TopID value become 20 and the other TopID not. After I retrieve the topics2 ID (i.e. 21) then I want the next image TopID become 21.

  2. #2
    Join Date
    Dec 1969

    Default Bad idea, anyway!

    Using -1 to "reserve" the place is *NOT* a good idea!<BR><BR>Suppose JOHN comes in and reserves a place by uploading an image. <BR><BR>Now BOB does the same. You will have images from TWO DIFFERENT people with TopID = -1 !!<BR><BR>Now JOHN submits the form and you do the update...and BOB&#039;s image gets John&#039;s ID!<BR><BR>That one is easy to fix: Use the Session.SessionID instead of -1 as the "placeholder".<BR><BR>But I don&#039;t have any clever ideas for your 2-topics, 2-images problem. What, for example, do you do if they upload 4 images but then only give you ONE topic??? Or they upload 1 image and four topics???? Which topic gets the image?<BR><BR>I think you are making this very hard for yourself. I&#039;d be real tempted to allow only one image and topic per page. After the one pair is submitted, you could Response.Redirect back to the same page (with the user&#039;s information already filled in) for another pair.<BR><BR>

Posting Permissions

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