ezmonet Posted April 27, 2010 Share Posted April 27, 2010 Let me start off that I am not that great of a programmer so my choice of words may not be clear so please bear with me. So I need a little nudge in the right direction please. Basically I have one page that takes data in and the another page to displays that data. When the user is browsing the data output page he can then click a button to send the date from one row to himself and then I need to mark that row as "inactive" so it wont display again. I have an array set up to query the MySQL database and then a table to display it and it works. However I don't know how to reference the data in each row when the user clicks the button. I am pretty sure that as soon as the array gets the data from MySQL and outputs it to the webpage it then loses track of the data. So I need to know how to keep the data in a variable or something like that so I can reference it edit it and then update MySQL. I am not looking for code to be written for me but more of a "you'll need to query the MySQL database and drop that information into a variable which you'll reference via an array" and from this I hope I can research the code needed. I really hope that I am explaining this correctly. Thanks Link to comment https://forums.phpfreaks.com/topic/199978-some-php-direction-please/ Share on other sites More sharing options...
andrewgauger Posted April 27, 2010 Share Posted April 27, 2010 1. When you say button do you mean such as found inside a <form> or an <a><img> a. If you are looking for a form handler for this function, you can set up a form that calls itself with method=get and throw a variable that makes something inactive (results.php?inactive=12) and that variable can relate to the field that you are looking to turn invisible. You can have at the top of the page if $_POST["submit"] and an if $_GET["invisible"] to handle the two scenarios (POSTED from query or GET from self) Every row will have its own form with a hidden tag. b. If you are trying to use JavaScript on an anchor, you build the table, reference the row to a function that will take the row out of the table. These updates will not be static unless you build a means for MySQL to track the inactivity. Do you have a separate table tracking these inactivities? 2. When you say you have an array that builds the table, does it print a row or are we talking about a multi-dimensional array that you can reference the contents directly? If it is multidimensional you can access the properties directly. Link to comment https://forums.phpfreaks.com/topic/199978-some-php-direction-please/#findComment-1049607 Share on other sites More sharing options...
ezmonet Posted April 27, 2010 Author Share Posted April 27, 2010 This is just simple PHP and MySQL. Here is the query of the MySQL and the table that gets created. Nothing fancy only because I don't know fancy. <?php mysql_connect('localhost', 'user', 'password') or die ("Unable to connect!"); mysql_select_db('Project_Tracking') or die ("Unable to select database!"); $query = "SELECT * FROM `web_database` WHERE Status != 'inactive'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); mysql_close(); while($row = mysql_fetch_row($result)){ $html = <<<TEXT <tr> <td><button type="submit">Email Me</button></td> <td align="center" width="80"> $row[1] </td> <td align="center" width="80"> $row[2] </td> <td align="center" width="80"> $row[3] </td> <td align="center" width="80"> $row[4] </td> <td align="center" width="80"> $row[5] </td> <td align="center" width="80"> $row[6] </td> </tr> TEXT; echo $html; } ?> Link to comment https://forums.phpfreaks.com/topic/199978-some-php-direction-please/#findComment-1049610 Share on other sites More sharing options...
andrewgauger Posted April 27, 2010 Share Posted April 27, 2010 It looks like what you want to do is to run an update against your table `web_database` UPDATE `web_database` SET (Status = 'inactive') WHERE id=$id I'd suggest that you change the button to a link (you can make an image that looks the way you want) and make the image an anchor that references this page as such: <a href=\""handler.php?inactive=$row[1]\"> Where handler.php is the name of the script. Then put in the top of your script (after defining the mysql_select_db) : if (isset($_GET['inactive']) { $query="UPDATE `web_database` SET (Status = 'inactive') WHERE id=${_GET['inactive']} "; mysql_query($query) or die ("failed!"); } [code=php:0] Where id is the name of your primary key and row[1] is the place of that primary key in the order of columns of your database. Link to comment https://forums.phpfreaks.com/topic/199978-some-php-direction-please/#findComment-1049614 Share on other sites More sharing options...
ezmonet Posted April 27, 2010 Author Share Posted April 27, 2010 I will try to wrap my head around this, and thanks! Link to comment https://forums.phpfreaks.com/topic/199978-some-php-direction-please/#findComment-1049619 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.