...

View Full Version : removing a record from a result set - SESSIONS?



Yakisoba
06-06-2005, 06:07 AM
I'm not sure if I'm posting this in the right forum, but I'll give it a shot...

Currently I have a php program that preforms a query on a MySQL db and returns the values to an .html file.

A typical example of the SELECT statments I've been using look like this:


$sql_select = "SELECT Genre, Title, Director, Year FROM movies WHERE Genre ='".$_POST['genre']."'";


the result is then stored in a result/record set:


$rs = mysql_query($sql_select);


The entire contents of the result set ($rs) is displayed in an html <table>. After the <table> is printed, the user may select rows that they would like to remove. Once the "remove" button is pressed that record is deleted from the .html table but NOT the db.

How can I remove a record(s) (and the associated <tr> (table row)) from the .html file but NOT the db?

Any suggestions?

Thanks

Yak

- Let me know if I should post this to the MySQL forum.

delinear
06-06-2005, 09:23 AM
You mean you want to somehow mark the row in the db so that on future queries it doesn't show up in the html? If so, you'd probably need to add another field to the database, like an "active" field and either set it to yes or no, then in your query just do:


$sql_select = "SELECT Genre, Title, Director, Year FROM movies WHERE Genre ='".$_POST['genre']."' AND active='yes'";

Then when you remove rows from the html, just do an update on those rows in the database and change their active field to 'no'.

Yakisoba
06-06-2005, 09:46 AM
not quite...

I don't want the data in the db to be manipulated in any way. Only the data that is contained in the result set.

For example:
SELECT * FROM table_name; - the results of this query are stored in a variable ($rs).

each row of the $rs is displayed in tabular form. Each row of the <table> also has a "remove" button.

when the user clicks on the "remove" button the row is removed from $rs and the table is refreshed (without re-running the original query).

Is this possible?

Thanks

Yak

markman
06-06-2005, 09:58 AM
To be honest I reallt think you should do a variable for $_POST['genre'] like :


$genre = $_REQUEST['genre'];
$sql_select = "SELECT Genre, Title, Director, Year FROM movies WHERE Genre ='$genre'";
$rs = mysql_query($rs);

delinear
06-06-2005, 11:26 AM
each row of the $rs is displayed in tabular form. Each row of the <table> also has a "remove" button.

when the user clicks on the "remove" button the row is removed from $rs and the table is refreshed (without re-running the original query).
Oh. Well, maybe sessions would be the way to do this, if you read all the data from the database into sessions then, when the user selects a row to remove you could pass the id for the row in the url then unset the row for the passed id, for instance (let's assume you have stored all the id's in a session array called rowdata):

if(isset($_GET['id']) && isset($_SESSION['rowdata'][$_GET['id']])) {
unset($_SESSION['rowdata'][$_GET['id']]);
}

Then just iterate through the session and create the table using the remaining stored row data.

Yakisoba
06-07-2005, 06:42 AM
Interesting...

delinear - that sounds like what I'm trying to do, unfortunatly I don't know much about session variables but they are high on my list of things to learn. No time like the present...

Would anyone be able to point me to some good web tutorials (regarding php sessions)?

Also, some examples on this matter would be appreciated.

Here is my code so far: (Note: everything worked fine until I started messing around with the session variables)


This file (select.php) runs the initial query and echo's the results into a <table>. In the first column of each row there is a "remove" button, when the user clicks the button it will run "remove.php" (onClick="remove.php"; i will probably change this to an href later)


error_reporting(E_ALL);

session_start();
session_register('rs');

include 'db_connect_movies.php';

//SELECT statment
$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();



When "remove.php" is executed the row (that the user clicked on) is removed from the session variable and the table is regenerated using the remaining values in the recordset.

remove.php


session_start();


if(isset($_GET['ID']) && isset($_SESSION['rs'][$_GET['ID']])) {
unset($_SESSION['rs'][$_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>";

}



I know remove.php is totally screwed up at the moment, any suggestions?

Thanks,

Yak

P.S. - markman


To be honest I reallt think you should do a variable for $_POST['genre'] like :
PHP Code:
$genre = $_REQUEST['genre'];
$sql_select = "SELECT Genre, Title, Director, Year FROM movies WHERE Genre ='$genre'";
$rs = mysql_query($rs);


Why?

delinear
06-07-2005, 10:49 AM
Well, a few things going on here. Firstly the example I suggested uses an auto-increment field id to identify the row that needs to be removed. I notice from your sql query that you don't make any call to an id. While it is possible to do this by passing the other fields to the url, it's much simpler if you use an id (and if you're not assigning an auto-incrementing id as your primary key in the database I'd highly recomment that you do so).

Next, you would only query the database when you load the page IF the session data doesn't already exist, otherwise you will just overwrite the session data each time which will defeat the purpose of having the session data.

Also, when you initially make the database call, you have to store the data as session data, you're not currently doing that.

Finally, in the onClick event you need to pass the id of the item you want to remove. Without passing that id you will just reload the page without removing anything.

Making those changes you should end up with something like...


error_reporting(E_ALL);

session_start();

// check whether to pull the data from the database
if(!isset($_SESSION['rs'])) {

include 'db_connect_movies.php';
$sql_select = "SELECT movie_id, Genre, Title, Director, Year FROM $db_table"; // requires an autoincrementing movie_id field in the database
$rs = mysql_query($sql_select);
$numrows = mysql_num_rows($rs);
for($i=0; $i < $numrows; $i++) {
$row[$i] = mysql_fetch_assoc($rs);
$_SESSION['rs'][$i] = mysql_fetch_assoc($rs);
}
}

// check whether to remove a row of data
if(isset($_GET['id'])) {
unset($_SESSION['rs'][$_GET['id']]);
}

//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

for($i=0; $i < count($_SESSION['rs']); $i++) {
echo '<tr><td><img src="../images/close.jpg" onClick="location.href=\'' . basename($_SERVER['PHP_SELF']) . '?id=' . $_SESSION['rs'][$i]['movie_id'] . '\'/></td><td>' . $_SESSION['rs'][$i]['Genre'] . '</td><td>' . $_SESSION['rs'][$i]['Title'] . '</td><td>' . $_SESSION['rs'][$i]['Director'] . '</td><td>' . $_SESSION['rs'][$i]['Year'] . '</td></tr>';
}

echo "</table>";
echo "</body></html>";


//free memory
mysql_free_result($rs);

//close the db
mysql_close();

I think that should do it although I have no way to test it right now so, any problems let me know and I'll take another look.

Just a couple of things to bear in mind - firstly as I said this code will only work if you have a movie_id field in your database so you will either need to create one or, if you already have one, you'll need to change the references to movie_id in the above code to point to your id field.

Secondly, I'm not 100% sure the javascript is right for the onClick although I'm reasonably sure it is.

Hope that helps a little.

Yakisoba
06-08-2005, 10:08 AM
I do use an AUTO_INCREMENT id field as a primary key in my db, so that won't be a problem...

When trying to run the code you provided the following happend:

(lets say my table has 6 records)

- A table with 6 rows was created, however only every second row was displayed. (first three rows of the table contained data, the last 3 were empty. Row #'s 2, 4, and 6 were displayed).

-The remove function does not seem to do anything at the moment.

I will screw around with it a little more tonight...

I appreciate the help.

Thanks

Yak

Kurashu
06-08-2005, 06:15 PM
$row[$i] = mysql_fetch_assoc($rs);
$_SESSION['rs'][$i] = mysql_fetch_assoc($rs);


That is the problem with the displaying every second row. Perosnally, this how I would have done that....



$rs = mysql_query($sql_select);
$i = 1;
while($row = mysql_fetch_assoc($rs))
{
$_SESSION['rs'][$i] = $row;
$i++;
}


But that's me.

delinear
06-08-2005, 07:20 PM
Oops, yeah I originally wrote it to output to $row then I realised it was quicker to put it directly into the session, must have forgot to remove the previous line, d'oh :D

delinear
06-08-2005, 07:31 PM
Try changing this:


if(isset($_GET['id'])) {
unset($_SESSION['rs'][$_GET['id']]);
}

To:


if(isset($_GET['id'])) {
for($i=0; $i < count($_SESSION['rs']); $i++) {
if($_GET['id'] == $_SESSION['rs'][$i]['movie_id']) {
unset($_SESSION['rs'][$i];
}
}
}

And change this:


echo '<tr><td><img src="../images/close.jpg" onClick="location.href=\'' . basename($_SERVER['PHP_SELF']) . '?id=' . $_SESSION['rs'][$i]['movie_id'] . '\'/></td><td>' . $_SESSION['rs'][$i]['Genre'] . '</td><td>' . $_SESSION['rs'][$i]['Title'] . '</td><td>' . $_SESSION['rs'][$i]['Director'] . '</td><td>' . $_SESSION['rs'][$i]['Year'] . '</td></tr>';

to this:


echo '<tr><td><a href="' . basename($_SERVER['PHP_SELF']) . '?id=' . $_SESSION['rs'][$i]['movie_id'] . '"><img src="../images/close.jpg" border="0" /></a></td><td>' . $_SESSION['rs'][$i]['Genre'] . '</td><td>' . $_SESSION['rs'][$i]['Title'] . '</td><td>' . $_SESSION['rs'][$i]['Director'] . '</td><td>' . $_SESSION['rs'][$i]['Year'] . '</td></tr>';

Hopefully that will fix all the stupid :rolleyes:

Yakisoba
06-09-2005, 06:40 AM
Oh man...getting close.

Here is what's happening now:

Kurashu - Your suggestion worked beautifully, I only had to change one thing. In your code you initialized the counter to 1 ($i = 1;), this worked, however it would skip the first row of the database (it was incremented to 2 before record 1 was printed).
I just initialized the counter to 0 ($i = 0;).

delinear - still having a little trouble with the "isset" code. For some reason "isset" always causes me grief.

I got the below piece of code to work (somewhat), for some reason when I clicked on the "remove" button it would remove the record below. Once the record was removed it would leave a blank row in the table (as apposed to regenerating the table minus that row). Also, the (deleted) record reappears when I attempt to remove another record.


if(isset($_GET['id'])) {
unset($_SESSION['rs'][$_GET['id']]);
}


I made a little change to the above code and now the proper record is removed, however the other two problems remain.

This is what I changed the above code to (nothing fancy);



$id = $_GET['id'] - 1;

if(isset($id)) {
unset($_SESSION['rs'][$id]);



I know it's a band-aid solution, but it works (for the moment).

I tried messing around with this...



if(isset($_GET['id'])) {
for($i=0; $i < count($_SESSION['rs']); $i++) {
if($_GET['id'] == $_SESSION['rs'][$i]['ID']) {
unset($_SESSION['rs'][$i];
}
}
}



...but have had no luck. Whenever I use this piece of code I can't get the table to print at all.

there has be something that I am overlooking.

Thanks again for the assistance.

Yak

delinear
06-09-2005, 07:30 AM
Ah, yeah sorry - it is right but the problem with the empty table row is caused because the numeric keys aren't reset, ie if you have rows 1,2,3,4,5 and you unset session 3 you will then have rows 1,2,4,5 but the for loop that draws the table still tries to print the empty row 3. All we have to do to fix that is reset the array keys for the session, array_values() is good for that. Here is the amended code:


error_reporting(E_ALL);
session_start();

// check whether to pull the data from the database
if(!isset($_SESSION['rs'])) {

include 'db_connect_movies.php';
$sql_select = "SELECT movie_id, Genre, Title, Director, Year FROM $db_table"; // requires an autoincrementing movie_id field in the database
$rs = mysql_query($sql_select);
$numrows = mysql_num_rows($rs);

for($i=0; $i < $numrows; $i++) {
$_SESSION['rs'][$i] = mysql_fetch_assoc($rs);
}
}

if(isset($_GET['id'])) {
for($i=0; $i < count($_SESSION['rs']); $i++) {
if($_GET['id'] == $_SESSION['rs'][$i]['movie_id']) {
unset($_SESSION['rs'][$i]);
}
}
$_SESSION['rs'] = array_values($_SESSION['rs']);
}

//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
for($i=0; $i < count($_SESSION['rs']); $i++) {
echo '<tr><td><a href="' . basename($_SERVER['PHP_SELF']) . '?id=' . $_SESSION['rs'][$i]['movie_id'] . '"><img src="../images/close.jpg" border="0" /></a></td><td>' . $_SESSION['rs'][$i]['Genre'] . '</td><td>' . $_SESSION['rs'][$i]['Title'] . '</td><td>' . $_SESSION['rs'][$i]['Director'] . '</td><td>' . $_SESSION['rs'][$i]['Year'] . '</td></tr>';
}

echo "</table>";
echo "</body></html>";

//free memory
mysql_free_result($rs);

//close the db
mysql_close();

Yakisoba
06-09-2005, 08:12 AM
almost...

When running the program for the first time the table generates with all values (as expected. I'll stick with the 6 row example). Then, I can click on the "remove" button on any row and that row dissappears (SWEET!!).

- Now I'm down to 5 rows -

But, after the first click things get a little crazy.

It appears that I am only allowed to remove one row from the <table>.

When I click to remove another row from the table that row dissapears however a 5 row table is regenerated. (and the value I previously removed reappears).



Yak

delinear
06-09-2005, 09:31 AM
Hmm... odd. That would suggest that the session data isn't maintaining for some reason, since it's obviously generating it anew from the database every time the page is refreshed. It was working fine this side, I set up some test data and it let me click one at a time until the whole table was removed. I don't know why the sessions would reset, I can't see anything in the code that might cause it :confused:

Try creating a script with this code:

<?php
session_start();
if(!isset($_SESSION['test'])) {
$_SESSION['test'] = 0;
} else {
echo $_SESSION['test'];
$_SESSION['test']++;
}
?>
Then run the script and refresh the page a few times, does the number increment or does it stick at 0 or 1?

The only thing I can see that ought to be changed (but shouldn't cause the problem you're having) is that the mysql_free_result and mysql_close are always being run whether they are needed or not, they ought to be moved inside the initial data retrieval loop like so:


if(!isset($_SESSION['rs'])) {

include 'db_connect_movies.php';
$sql_select = "SELECT movie_id, Genre, Title, Director, Year FROM $db_table"; // requires an autoincrementing movie_id field in the database
$rs = mysql_query($sql_select);
$numrows = mysql_num_rows($rs);

for($i=0; $i < $numrows; $i++) {
$_SESSION['rs'][$i] = mysql_fetch_assoc($rs);
}

//free memory
mysql_free_result($rs);

//close the db
mysql_close();
}
But like I said, that's just incidental it shouldn't be causing this behaviour.

Yakisoba
06-09-2005, 10:29 AM
so close yet so far...

alright, now try not to laugh when I tell you this; I can't get that little $_SESSION test program to do anything. Could it be possble this has something to do with the way I have SESSIONS set up in my php.ini file?

you are right...the code does look tight. The only thing I can think of is that its my .ini file. I could post that section (of the .ini) if you would like?

Yak

delinear
06-09-2005, 10:46 AM
Yeah, basically the first time you run the script it should display a blank page, then when you refresh, if the session works it will display 0 then 1, 2, 3 etc incrementing each time you refresh.

If that's not working then it would seem your session data just isn't being passed on at all. I'm not sure why this might be as I've never experienced it before, you could post the ini data, it might be something in your config, like maybe your PHP is set to use only cookies and your browser is refusing them or something. I'm no ini expert but I'm sure if something's wrong in there someone will spot it.

Yakisoba
06-09-2005, 12:13 PM
Here is the SESSION section of my php.ini, maybe this can shed some light on my problems... (I hope).



[Session]
; Handler used to store/retrieve data.
session.save_handler = files

; Argument passed to save_handler. In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this
; variable in order to use PHP's session functions.
;
; As of PHP 4.0.1, you can define the path as:
;
session.save_path = "C:\Temp"
;
; where N is an integer. Instead of storing all the session files in
; /path, what this will do is use subdirectories N-levels deep, and
; store the session data in those directories. This is useful if you
; or your OS have problems with lots of files in one directory, and is
; a more efficient layout for servers that handle lots of sessions.
;
; NOTE 1: PHP will not create this directory structure automatically.
; You can use the script in the ext/session dir for that purpose.
; NOTE 2: See the section on garbage collection below if you choose to
; use subdirectories for session storage
;
; The file storage module creates files using mode 600 by default.
; You can change that by using
;
; session.save_path = "N;MODE;/path"
;
; where MODE is the octal representation of the mode. Note that this
; does not overwrite the process's umask.
;session.save_path = "/tmp"

; Whether to use cookies.
session.use_cookies = 1

; This option enables administrators to make their users invulnerable to
; attacks which involve passing session ids in URLs; defaults to 0.
; session.use_only_cookies = 1

; Name of the session (used as cookie name).
session.name = PHPSESSID

; Initialize session on request startup.
session.auto_start = 0

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0

; The path for which the cookie is valid.
session.cookie_path = \

; The domain for which the cookie is valid.
session.cookie_domain =

; Handler used to serialize data. php is the standard serializer of PHP.
session.serialize_handler = php

; Define the probability that the 'garbage collection' process is started
; on every session initialization.
; The probability is calculated by using gc_probability/gc_divisor,
; e.g. 1/100 means there is a 1% chance that the GC process starts
; on each request.

session.gc_probability = 1
session.gc_divisor = 1000

; After this number of seconds, stored data will be seen as 'garbage' and
; cleaned up by the garbage collection process.
session.gc_maxlifetime = 1440

; NOTE: If you are using the subdirectory option for storing session files
; (see session.save_path above), then garbage collection does *not*
; happen automatically. You will need to do your own garbage
; collection through a shell script, cron entry, or some other method.
; For example, the following script would is the equivalent of
; setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes):
; cd /path/to/sessions; find -cmin +24 | xargs rm

; PHP 4.2 and less have an undocumented feature/bug that allows you to
; to initialize a session variable in the global scope, albeit register_globals
; is disabled. PHP 4.3 and later will warn you, if this feature is used.
; You can disable the feature and the warning separately. At this time,
; the warning is only displayed, if bug_compat_42 is enabled.

session.bug_compat_42 = 0
session.bug_compat_warn = 1

; Check HTTP Referer to invalidate externally stored URLs containing ids.
; HTTP_REFERER has to contain this substring for the session to be
; considered as valid.
session.referer_check =

; How many bytes to read from the file.
session.entropy_length = 0

; Specified here to create the session id.
session.entropy_file =

;session.entropy_length = 16

;session.entropy_file = /dev/urandom

; Set to {nocache,private,public,} to determine HTTP caching aspects
; or leave this empty to avoid sending anti-caching headers.
session.cache_limiter = nocache

; Document expires after n minutes.
session.cache_expire = 180

; trans sid support is disabled by default.
; Use of trans sid may risk your users security.
; Use this option with caution.
; - User may send URL contains active session ID
; to other person via. email/irc/etc.
; - URL that contains active session ID may be stored
; in publically accessible computer.
; - User may access your site with the same session ID
; always using URL stored in browser's history or bookmarks.
session.use_trans_sid = 0

; Select a hash function
; 0: MD5 (128 bits)
; 1: SHA-1 (160 bits)
session.hash_function = 0

; Define how many bits are stored in each character when converting
; the binary hash data to something readable.
;
; 4 bits: 0-9, a-f
; 5 bits: 0-9, a-v
; 6 bits: 0-9, a-z, A-Z, "-", ","
session.hash_bits_per_character = 5

; The URL rewriter will look for URLs in a defined set of HTML tags.
; form/fieldset are special; if you include them here, the rewriter will
; add a hidden <input> field with the info which is otherwise appended
; to URLs. If you want XHTML conformity, remove the form entry.
; Note that all valid entries require a "=", even if no value follows.
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"


Yak

delinear
06-09-2005, 12:26 PM
Hmm, well I'm no expert but a couple of things that might be causing you problems are:

session.save_path = "C:\Temp"

The sessions work (as I understand it) by saving a cookie on the server instead of the client machine. If this session cookie is saved in a directory defined as the temporary directory on the server it could well be the case that your session cookies are being deleted after the script has executed. You could try changing this directory and see if it has any affect.

session.use_trans_sid = 0

If your browser is set to reject cookies or limits the cookies it accepts, the above line would cause sessions not to work since it prevents the session id from being passed in the url if cookies are disabled. Two ways around this are to either change the setting to 1 to enable url session id's or to explicitly add the session id to the links on your script.

Those are the only potential problems I can see, but as I said that's not really my area but it's where I'd start.

Yakisoba
06-10-2005, 02:56 AM
Currently I'm using PHP 5.0.4 with Apache 2.0.53...

The session save path (session.save_path = "C:\Temp") seems to be correct, as everytime I run your session test script a new session ID is created in the C:\Temp folder. For some reason its not sending the informaition back.

Could this be a problem in my Apache .httpd file?


I also tired your second suggestion (session.use_trans_sid = 1), still no luck.

anymore suggestions? anyone?

I'm running low on ideas here...

Yak

delinear
06-10-2005, 10:18 AM
Hmm, well if it's a linux/apache config problem then I'm probably out of my depth too, sorry. Wish I could be more help :confused:

Yakisoba
06-13-2005, 03:29 AM
Don't worry about it, I wouldn't have been able to make it this far without your help. Thanks again.

In one of your posts you mentioned that you have the code working on your end. If you have a moment take a look at this final piece of code and let me know if you see anything wrong (I just want to rule out the fact that I may have a little typo or some other stupid mistake in my code that I'm overlooking before I start a thread on sessions and php.ini configurations).



session_start();
error_reporting(E_ALL);


// check whether to pull the data from the database
if(!isset($_SESSION['rs'])) {

include 'db_connect_movies.php';
$sql_select = "SELECT ID, Genre, Title, Director, Year FROM $db_table";
$rs = mysql_query($sql_select);
$numrows = mysql_num_rows($rs);

for($i=0; $i < $numrows; $i++) {
$_SESSION['rs'][$i] = mysql_fetch_assoc($rs);
}
}

if(isset($_GET['id'])) {
for($i=0; $i < count($_SESSION['rs']); $i++) {
if($_GET['id'] == $_SESSION['rs'][$i]['ID']) {
unset($_SESSION['rs'][$i]);
}
}
$_SESSION['rs'] = array_values($_SESSION['rs']);
}

//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
for($i=0; $i < count($_SESSION['rs']); $i++) {
echo '<tr><td><a href="' . basename($_SERVER['PHP_SELF']) . '?id=' . $_SESSION['rs'][$i]['ID'] . '"><img src="../images/close.jpg" border="0" /></a></td><td>' . $_SESSION['rs'][$i]['Genre'] . '</td><td>' . $_SESSION['rs'][$i]['Title'] . '</td><td>' . $_SESSION['rs'][$i]['Director'] . '</td><td>' . $_SESSION['rs'][$i]['Year'] . '</td></tr>';
}

echo "</table>";
echo "</body></html>";

//free memory
mysql_free_result($rs);

//close the db
mysql_close();



Anyone else with suggestions, please let me know.

Thanks,

Yak

delinear
06-13-2005, 10:24 AM
Hmm, only one final thing I'd suggest, it might be a bit crazy but anything's worth a try. Try and remove the line:

//free memory
mysql_free_result($rs);

I was just thinking, if $rs was accessing the session $rs (ie, if you have global variables enabled) then I don't know what effect mysql_free_result would have, it might clear all the data out of $_SESSION['rs'] at the end of each page refresh. It's a long shot and I'm not sure that's even how it works, but it's worth a try :o

Then again, that wouldn't explain why sessions aren't working on other scripts, like the test script.

Yakisoba
06-14-2005, 05:53 AM
no luck...

I'll have to figure this session problem out before I start working on the ADD feature as the concept is similar.

i.e.
The table will start out blank...there will be a list of buttons with the directors name in it. When the user clicks on the button it runs a SELECT query and returns (and displays) the most current movie WHERE Director="whatever". This value is stored in a SESSION (if I get it working) and is only removed by using the code above.

Its basically the opposite of what was done above. Any suggestions on the best way of doing this would be appretiated, however I need to get my sessions working properly at the moment.

Thanks,

Yak



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum