Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removing rows from record set - sessions?

Status
Not open for further replies.

atsea

Technical User
Feb 27, 2005
51
JP
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)
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
 
What errors do you get? Is remove.php even started?

You have misunderstood what's in the variable "$rs". It is pointer to the record set array not the array itself. Also, you have stored it in the session array much too early in your code. It should be stored after it is set.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top