owatagal Posted April 20, 2005 Share Posted April 20, 2005 I'm just trying to check the logic of this idea, before I have to sit down and dump it in a much more complicated form. Say I have a set of data associated with links, and this data gets saved into a link table in my database. To edit the data, I have a form that pulls the information out of the database and outputs it something like this: ><input type="hidden" name="url_id" value="1" /> <input type="text" name="category" value="homepage" /> <input type="text" name="url" value="homepage.com" /> <input type="text" name="linktext" value="Home Page" /> Updating a single link isn't a problem. But what if I have a variable number of links, tied to an author ID? The author ID is defined elsewhere on the form, and doesn't play into this except that for one author I might need to update six links and for another eight--so the number of links will change constantly. Can I turn "hidden" and "text" fields into arrays like I would use radio buttons or check boxes? So the code would look like this: ><input type="hidden" name="url_id[]" value="1" /> ... etc And then on the results page, I should just have to count up the number of items in one of the arrays (say url_id[]) and then use a loop like: >for ($a=0; $a<$count; $a++) { update database, setting category=$category[$a], url=$url[$a], linktext=$linktext[$a] where url_id = $url_id[$a] } I know that's not valid PHP/MySQL, but is the logic right? It wouldn't matter how many sets of link data I have, because each element would be its own array. But will the data be stored in the correct order? When it gets to $a=7, will the seventh value in each array all correspond to the seventh link? Everything else I've tried isn't working, and I'm tired of testing broken code. If anyone can confirm the logic of this looks good, at least I'll know that, *in theory*, I have a workable model. It'll make error-fixing more tolerable... [i'm not the least bit frustrated... not me. No way.] Quote Link to comment Share on other sites More sharing options...
section31 Posted April 20, 2005 Share Posted April 20, 2005 looks fine to me. 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.