Base Posted April 8, 2007 Share Posted April 8, 2007 Hi there, this is my virgin post in PHP Freaks, and i do hope you'll treat me real nice Anyway! I have come across a problem with some coding work that i am doing. My problem is the following: Presenters in the radio station, are shown in order of ID. What i want to be able to do, is edit the order in which they are shown, by editing the ID. My problem, is that when i process the form the script has no way of telling what the field names are, as they are not pre defined, because i have put the code in a while loop, to get all of the DJ's names & id's out. My code is below: <? $query = "SELECT * FROM profiles ORDER BY ID DESC"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { ?> <form method="post" action="viewpage.php?page_id=15"> <table align="center"> <tr> <td align="right">DJ Name:</td> <td><input name="name_<?php echo $row['ID']; ?>" type="text" id="<?php echo $row['ID']; ?>" value="<?php echo $row['djname']; ?>" size="40" maxlength="250" /></td></tr> <tr> <td align="right">Order:</td> <td><input name="id" type="text" id="djname" value="<?php echo $row['ID']; ?>" size="40" maxlength="250" /></td></tr> <tr><td> </td><td><input type="submit" name="submit" value="Modify" /> <input type="submit" name="Submit" value="Delete" /><input type="hidden" name="id" value="<?php echo $row['djname']; ?>" /></td></tr> </table> </form> <br><br><br><br> <?php } ?> So as you can see, it displays the DJ's by ID decending. I need to be able to: Edit all of the ID's to correspond to the order that i set (so myseld as id 1, my co-presenter as id 2 and so on) So if i submit the form with the buttons that are allready there, then it will only recognise the change to that specific form, rather than all the forms that are displayed. And thats about it! I hope i have made myself clear, i have tried to explain it well, but seeing as i don't really understand it myself, i won't have done that well. Can i request that when people reply they don't say like "oh google this: " or somthing like that, because when i do google things like that i just get more and more confused! Argh! So if someone could be fantastic and maybe give me the code, then i would be willing to donate maybe $20 to PHP Freaks or somthing like that. But thanks very much for reading, and i hope you can awnser my question! Cheers! Base Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 ok so the page displays the ids. the form resets the ids in order that you want them??? of the ids are organised acording to another field, eg presenter, co-preseneter, producer etc...????? Quote Link to comment Share on other sites More sharing options...
Base Posted April 8, 2007 Author Share Posted April 8, 2007 The page code that i sent you displays the following: DJ Name: ID in the database: What i need to be able to do is: Edit the ID in the database, so that when i display it, it comes up in the order that i want Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 ok then you have a small input form next to the id, and then a button whereever to submit. somehow linkthe old id with the new then you loop through the $_REQUEST array in the next page, and "UPDATE table SET ID = "$_REQUEST[$indx]."WHERE ID = "$_REQUEST[$index."old"];, increment $indx at the end of the foreach......... this should work, i dont have time to have a full code for you, but if noone else answeres, then ask me in about 6 hours if imon, PM me.... good luck Quote Link to comment Share on other sites More sharing options...
Base Posted April 8, 2007 Author Share Posted April 8, 2007 I'm sorry, you did explain that quite well and i thankyou very much for that. But i understood none of that! :'( Sorry to be a pain, but can someone give me the full code? Really sorry to be such a nag! Base Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 ok, so you make your fields and then send it to a script as POST data..... foreach($_POST as $key => $Val) { if ($key != "%old") { $SQL = "UPDATE Table SET User_ID = ".$Val." WHERE User_ID = ".$Val."old"; $query = mysql_query($SQL) or die( "query failed".mysql_error()); unset($SQL, query); } else {continue;} this should work what you could do if catch this with a get value at the top of the page, then re get the user_ids and do al the stuff in the same page.... you want me to explain this???? Quote Link to comment Share on other sites More sharing options...
Base Posted April 8, 2007 Author Share Posted April 8, 2007 ok, so you make your fields and then send it to a script as POST data..... foreach($_POST as $key => $Val) { if ($key != "%old") { $SQL = "UPDATE Table SET User_ID = ".$Val." WHERE User_ID = ".$Val."old"; $query = mysql_query($SQL) or die( "query failed".mysql_error()); unset($SQL, query); } else {continue;} this should work what you could do if catch this with a get value at the top of the page, then re get the user_ids and do al the stuff in the same page.... you want me to explain this???? I swear i must be the most newbish person on here :'( If i give you my code, could you please do me the most massive favour and re-do my code? I know this is asking allot, and if you don't want too, then thats OK, and i understand. Here is my current reciving file: <?php $id = $_POST['***']; $djname = $_POST['djname']; $query = "UPDATE profiles SET ID = '$ID' WHERE djname = '$djname'"; //Execute the query. $result = mysql_query($query) or die(mysql_error()); echo "<center><strong>ID order modified.</strong></center>"; ?> Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 Base, check your mesages Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted April 8, 2007 Share Posted April 8, 2007 Base this is the file that you gave me. as i said i cant test it becauase you have the database etc. this should do what you want. if not im not sure shat to do....... youll have to post on the forum hope it works PC Nerd [attachment deleted by admin] 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.