eightFX Posted October 12, 2007 Share Posted October 12, 2007 Hey everyone, Looking for a little help, not sure how to do what I am trying to do, or if it is even possible, but figured I would ask anyhow. What I am trying to do is derive a url from another field in the table. For example: Table: pages Table Fields: ID | TITLE | CONTENT | URL ID is auto-incremented. TITLE is inputted. CONTENT is inputted. URL is http://myurl.com/?page=ID (ID being the auto incremented field) I think I could use an update after adding the data initially to create it, but I was hoping there was a better way to do it. $query = INSERT INTO pages (ID, TITLE, CONTENT, URL) VALUES (0, 'This is my title', 'This is my content', 0) then do a SELECT query choosing the ID and TITLE to get the ID, then do a UPDATE query on URL field to include http://myurl.com/?page=$row[iD]. Not sure if any of this makes sense which could be why I am having trouble trying to think it through. Thanks for any help! Quote Link to comment Share on other sites More sharing options...
eightFX Posted October 12, 2007 Author Share Posted October 12, 2007 If I can make this any clearer by supplying more information let me know. Quote Link to comment Share on other sites More sharing options...
fenway Posted October 12, 2007 Share Posted October 12, 2007 Don't do that ... do this in your PHP code. You don't need the url field at all if it's always going to be dependent on the PK. And don't use "0" for the PK in an insert... leave that field out entirely. Quote Link to comment Share on other sites More sharing options...
eightFX Posted October 12, 2007 Author Share Posted October 12, 2007 So in php just refer to the id instead. such as.. href=http://myurl.com/page='.$row[id].' ... etc I have done what I wrote above before, thought it might be easier to store it all in the database, oh well. Sounds good, thanks Fenway! P.S. Go Red Sox! Game 1 of ALCS! Hoorah! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.