Currently I have a .php file that runs a query on a MySQL db and displays the results as a table in an .html file (using <iframe>). In addition, the first column of each row contains a "remove" button.
When the user clicks the "remove" button that row is removed from the result set and the table is refreshed.
Essentially the initial query is only executed once, the array is stored in a session variable (i think). Rows are removed from the result set NOT the db.
I just started working with session variables and I seem to be having problems setting and manipulating them.
Here is some of my code I have so far:
select.php (preforms the initial query, stores the result set into a variable, displays output in .html)
notice that the first column has an image with an onClick event (this is the remove button).
when the img is clicked on "remove.php" will run. This will be responsible for removing the row from the result set and reconstructing the table with the new results.
Right now the above "remove.php" doesn't work, I'm pretty sure it has to do with my use (or lack) of session variables.
any guidance would be greatly appreciated.
Thanks,
atsea
When the user clicks the "remove" button that row is removed from the result set and the table is refreshed.
Essentially the initial query is only executed once, the array is stored in a session variable (i think). Rows are removed from the result set NOT the db.
I just started working with session variables and I seem to be having problems setting and manipulating them.
Here is some of my code I have so far:
select.php (preforms the initial query, stores the result set into a variable, displays output in .html)
Code:
session_start();
//session_register('rs');
$_SESSION['recordset'] = $rs;
error_reporting(E_ALL);
include 'db_connect_movies.php';
//SELECT statment
//$sql_select = "SELECT Genre, Title, Director, Year FROM $db_table WHERE Genre ='".$_POST['genre']."'";
$sql_select = "SELECT Genre, Title, Director, Year FROM $db_table";
//result set
$rs = mysql_query($sql_select);
//creating the table /w headers
echo "<html><body>";
echo "<table border='1' cellspacing='0'><tr><td><img src='../images/close.jpg' /></td><td>Genre</td><td>Title</td><td>Director</td><td>Year</td></tr>";
//row for each record
while ($row = mysql_fetch_array($rs)) {
echo "<tr><td><img src='../images/close.jpg' onClick='remove.php'/></td><td>" . $row['Genre'] . "</td><td>" . $row['Title'] . "</td><td>" . $row['Director'] . "</td><td>" . $row['Year'] . "</td></tr>";
}
echo "</table>";
echo "</body></html>";
//free memory
mysql_free_result($rs);
//close the db
mysql_close();
notice that the first column has an image with an onClick event (this is the remove button).
when the img is clicked on "remove.php" will run. This will be responsible for removing the row from the result set and reconstructing the table with the new results.
Code:
session_start();
if(isset($_GET['ID']) && isset($_SESSION['recordset'][$_GET['ID']])) {
unset($_SESSION['recordset'][$_GET['ID']]);
echo "<html><body>";
echo "<table border='1' cellspacing='0'><tr><td><img src='../images/close.jpg' /></td><td>Genre</td><td>Title</td><td>Director</td><td>Year</td></tr>";
while ($row = mysql_fetch_array($rs)) {
echo "<tr><td><img src='../images/close.jpg' onClick='remove.php'/></td><td>" . $row['Genre'] . "</td><td>" . $row['Title'] . "</td><td>" . $row['Director'] . "</td><td>" . $row['Year'] . "</td></tr>";
}
echo "</table>";
echo "</body></html>";
}
Right now the above "remove.php" doesn't work, I'm pretty sure it has to do with my use (or lack) of session variables.
any guidance would be greatly appreciated.
Thanks,
atsea