close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Using Session Variables to create a shopping cart selection system

Thread began 2/13/2023 7:53 am by yogastudents362523 | Last modified 2/22/2023 11:02 am by Ray Borduin | 352 views | 7 replies |

yogastudents362523

Using Session Variables to create a shopping cart selection system

Hello,

I am having trouble controlling Session Variables.

Your WebAssist Cookies menu item allows me to use the following example code snippet:

<?php
@session_start();
if (!isset($_SESSION["TemporaryCart"])) {
$_SESSION["TemporaryCart"] = "".($rsQueryRecordSet->getColumnVal("OnlyOneItem")) ."";
}
?>

But what I in fact want is the entire array of items in that initial query. But nothing I have tried does this successfully.


I believe, for marketing purposes, that it would be effective if people thinking of purchasing a ticket could preview classes and imagine what they might attend. But I do not want to grant database access to such unpaid and unvetted previewers. It would surely open me up to attacks of all kinds.

I have already created the kind of a "shopping cart experience" I want, and it is already available to my paid ticket holders. But it of course runs by putting their selections into a database. They can browse the entire set of Classes for that day, and then select 4 ... 2 to "livestream", and 2 for later on demand viewing. Those go into the database.


For unpaid people, I thought Session Variables would work better. So I just want to fill a Session Variable with all the classes for that day as extracted from my database. Then previewers can select them from the available items in Session. I can create subarrays of their selections??


But I unfortunately cannot get the results from an initial recordset query into a Session Variable I can manipulate,


I have attached a copy a file that I want to emulate. I also provide credentials for a live version on the server so you can observe what I have done in action if necessary.

I believe that once I get the above code snipper WebAssist Tools provide me working on an entire array, rather than on a single item, I will have the means to select single items from the resulting array, I think I will then be fine with the usual key => variable PHP system.

Thank you for your help.

Attached Files
cart_sessions_iyengar_daily_Mon.php
Sign in to reply to this post

Ray BorduinWebAssist

I don't really understand fully what you want to do. It sounds like you want to save an array in the session, but I don't understand the trigger you want to use or if you are adding one item at a time or multiple. If you provide more background about that then I'm sure I can help.

For instance, if you wanted to save all of the rows in a recordset into a session variable array it would be something like:

<?php
@session_start();
if (!isset($_SESSION["TemporaryCart"])) {
$_SESSION["TemporaryCart"] = $rsQueryRecordSet->getColumnArray("ColumnName"));
}
?>

Sign in to reply to this post
Did this help? Tips are appreciated...

yogastudents362523

Hello Ray,

Thank you for your response.

I have done more researching. I have found a tutorial. And I now realize that I was asking about something far more complex than I had initially thought. I can well understand why you are not comprehending what I would like to do!!

I am going to work through the underneath tutorials.

https://www.plus2net.com/php_tutorial/array-session.php
https://www.plus2net.com/php_tutorial/array-session-demo.php

If I still cannot figure out what to do, I will hopefully be better informed.

Thank you for your kindness.

I am genuinely wishing you all possible wellness and good health.

I am sorry for the inconvenience.

My sincere gratitude again.

Sign in to reply to this post

yogastudents362523

Hello,

That tutorial has not helped.

My main issue is how to convert an entire MySQL recordset into a Session Array or Session Variable that is also an associative array giving me access to all data in the original recordset,

I trialled the following code snippet you suggested:

<?php
@session_start();
if (!isset($_SESSION["MonclassID"])) {
$_SESSION["Monclassid"] = $ClassesCopy->getColumnArray('ClassID');
}
?>

The following code snippet:

<?php
var_dump($_SESSION["Monclassid"]);
?>

successfully lists the ID for every Monday class, the result being:

array(12) { [0]=> int(2131) [1]=> int(2086) [2]=> int(2093) [3]=> int(2077) [4]=> int(2089) [5]=> int(2065) [6]=> int(2078) [7]=> int(2106) [8]=> int(2102) [9]=> int(2120) [10]=> int(2083) [11]=> int(2109) }

This is of only limited use because the only way I can see to access data such as StartTime, ClassTitle, ClassLength and etc. is the roundabout way of doing for every column what I did for ClassID, which is return to getColumnArray() and create a new and disctinct Session Array just for that.

I then have to carefully correlate all array pointers to ensure I always have the correct data items for each ClassID.

Is there really no way to create a Session Array or Session Variable that is simply an associative array that mirrors a MrSQLi query?
Could I not then simply loop through that Session Array as easily as your tools let me loop through a MySQLi query?

Thank you.

Sign in to reply to this post

Ray BorduinWebAssist

php:
<?php

@session_start();
if (!isset(
$_SESSION["MonclassID"])) {
$_SESSION["Monclassid"] = $ClassesCopy->Results;
}
?>



That will give you the entire recordset as an array in the session.

Sign in to reply to this post
Did this help? Tips are appreciated...

yogastudents362523

Hi Ray,

Thank you.
I do not know how I missed you giving me the above. I had just come on to say I had found myGetRow() which I felt I could loop through, but what you have provided is even better.

Ah, the joys of ignorance.

Thank you,
KAB

Sign in to reply to this post

yogastudents362523

Hello,

When i use:

$_SESSION["AllMonClasses"] = $rsClassesCopy->Results;

to create a Session array; and then use:

var_dump($_SESSION["AllMonClasses"]);

I get the complete listing of data from the orignal database query.

But when I try to access some specific data by for example trying:

var_dump($_SESSION["AllMonClasses"]["ClassID"]);

I get "Null"

And then when I try:
foreach ($_SESSION['AllMonClasses'] as $key => $value) {
echo $key . " " . $value . "<br /><br />";
}
I get only:
"0 Array
1 Array
2 Array
....
etc.

I do not get either the keys or the values.

My preference would be a "while loop" that also allowed me to access the individual Sessio Array values through the associative Session Array keys.

I am sorry for the inconvenience. Everything I read says:
$_SESSION["AllMonClasses"]["ClassID"]


should work to access that data, but that does not seem to be the case for me.

How can I access in a controllable way the items in that Session Array?

Thank you.
KAB

Sign in to reply to this post

yogastudents362523

PLEASE CLOSE

Hello

Please close and ignore this ticket.
I have found another way around this issue.

Thank you

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...