trg86 Posted October 27, 2012 Share Posted October 27, 2012 Hey guys, me again. I want to thank you again for helping resolve the issue I had earlier today with the php sessions. You all rock! I have approached an issue that I am not quite sure how to do exactly. In reference to the same content of my previous post, I have a form that, when filled out by a user, adds it's contents to a MySQL database and displays them in a very nice interface I have designed. Along with all of this, my system automatically adds 'options' to each display of input, i.e. 'edit' 'delete', etc. These work flawlessly. My question is, I am wanting to add a couple of new features that would require for the displayed information to be removed from the main page then moved and displayed on it's new page, consider this an option like 'Archive' What would be the best way for me to do this, code wise? Thanks again in advance for your assistance, this community is definitely very helpful. Quote Link to comment Share on other sites More sharing options...
requinix Posted October 27, 2012 Share Posted October 27, 2012 (edited) Keep a flag with the records that indicates whether something is archived or not. The main page shows the ones with archived=0 and the archive page shows the ones with archived=1. [edit] Assuming that "archived" doesn't entail anything more than where the records show up. Like whether they've been backed up somewhere. Edited October 27, 2012 by requinix Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 27, 2012 Author Share Posted October 27, 2012 Nope, no backed up data, just need to be able to move it to an 'archived' page, from the main page, if the user selects the option. I'm just not quite sure where to start... Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 27, 2012 Share Posted October 27, 2012 Add a field to the table called "archived." Set that field to 0. Add a button called "archive this" that will flip the "archived" field on a post to 1. Have your main page only show items where archived = 0. Have an archive page if you wish, which only shows archived = 1. What else are you looking for here? Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 27, 2012 Author Share Posted October 27, 2012 (edited) I'm not quite sure of the exact code I should use to do this. Edited October 27, 2012 by trg86 Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 27, 2012 Author Share Posted October 27, 2012 Do I add the 'archive' table to the same mysql table I have it pulling the results from? or create a new table within the same database? Quote Link to comment Share on other sites More sharing options...
jcbones Posted October 27, 2012 Share Posted October 27, 2012 Just add an archive COLUMN, not a separate table. You would modify this with an update, just as you are with your 'edit' buttons. Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 27, 2012 Author Share Posted October 27, 2012 Just add an archive COLUMN, not a separate table. You would modify this with an update, just as you are with your 'edit' buttons. Oh okay, I understand better now, sounds simple enough. Thanks! I will let you know if I need any further assistance. Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 27, 2012 Author Share Posted October 27, 2012 What would the proper settings be for this column in the database? Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 27, 2012 Share Posted October 27, 2012 Boolean (int 1) Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 27, 2012 Author Share Posted October 27, 2012 Boolean (int 1) I have it: `archive` INT( 1 ) NOT NULL ; should work? Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 27, 2012 Author Share Posted October 27, 2012 (edited) Add a field to the table called "archived." Set that field to 0. Add a button called "archive this" that will flip the "archived" field on a post to 1. Have your main page only show items where archived = 0. Have an archive page if you wish, which only shows archived = 1. Additionally, what would be the best way to do this? I already have the button created and in place Edited October 27, 2012 by trg86 Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 27, 2012 Share Posted October 27, 2012 (edited) Submit the form with an id of what you're archiving in the url such as archive.php?id=id Just call it by using $id = mysql_real_escape_string($_GET['id']); Then use sql to update the information $sql = "UPDATE `table` SET `archive` = '1' WHERE `id` = '$id'"; To call all of them that aren't archived just use a while loop and a where clause as followed: $sql = "SELECT * FROM `table` WHERE `archive` = '0'"; $result = mysql_query($sql,$connection) or die("Error connecting to the database"); while($row = mysql_fetch_array($result)) { // How you want to display it here. Examples shown below $title = $row['title']; $info = $row['info']; $id = $row['id']; // Using so many echos to keep it easy to read echo "$title<br>"; echo "$info<br>"; echo "<form action='archive.php?id=$id' method='post'>"; echo "<input type='submit' value='Archive This'>"; echo "</form>"; } Edited October 27, 2012 by ExtremeGaming Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 28, 2012 Author Share Posted October 28, 2012 (edited) Submit the form with an id of what you're archiving in the url such as archive.php?id=id Just call it by using $id = mysql_real_escape_string($_GET['id']); Then use sql to update the information $sql = "UPDATE `table` SET `archive` = '1' WHERE `id` = '$id'"; To call all of them that aren't archived just use a while loop and a where clause as followed: $sql = "SELECT * FROM `table` WHERE `archive` = '0'"; $result = mysql_query($sql,$connection) or die("Error connecting to the database"); while($row = mysql_fetch_array($result)) { // How you want to display it here. Examples shown below $title = $row['title']; $info = $row['info']; $id = $row['id']; // Using so many echos to keep it easy to read echo "$title<br>"; echo "$info<br>"; echo "<form action='archive.php?id=$id' method='post'>"; echo "<input type='submit' value='Archive This'>"; echo "</form>"; } Thank you for the example, although I did not need the whole code, just needed to add this option to my current structure. I also took previous advice that I needed to set it up just like my already complete 'edit' function, which I have done. I have this successfully working now, just need to make the archive page to display just the archived leads... Edited October 28, 2012 by trg86 Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 28, 2012 Share Posted October 28, 2012 What's the best way to do what? We don't write coded for you here unless you're very lucky and ExtremeGaming happens to be around. If you honestly can't figure this out, either hope to keep receiving his good graces, or pay someone to implement it for you. Quote Link to comment Share on other sites More sharing options...
jcbones Posted October 28, 2012 Share Posted October 28, 2012 To show archive's just change the query: $sql = "SELECT * FROM `table` WHERE `archive` = 1"; Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 28, 2012 Author Share Posted October 28, 2012 To show archive's just change the query: $sql = "SELECT * FROM `table` WHERE `archive` = 1"; Already done! Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 28, 2012 Author Share Posted October 28, 2012 Alrighty, I have received enough help, I have this fully functioning now, thanks everybody! Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 28, 2012 Share Posted October 28, 2012 (edited) ExtremeGaming happens to be around. lol. I try to leave all code snippets unfinished so they can add on and edit what they need. Sometimes I go a little overboard Edited October 28, 2012 by ExtremeGaming 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.