close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Using Session IDs to filter Recordset isn't looping through all of the IDs

Thread began 9/12/2013 10:47 am by troyd | Last modified 9/12/2013 3:04 pm by troyd | 513 views | 2 replies |

troyd

Using Session IDs to filter Recordset isn't looping through all of the IDs

I seem to be tripping over some basics here. Not sure what I am forgetting.
I am filtering a recordset from stored $_SESSION(s) BUT it's only filtering to the first ID of each $_SESSION.

Basically I have a 3 Step form that builds up ID's as they are selected and posted.
They are stored in $_SESSION(s,) one for each page.

The sessions are being stored ok as I move through each step.
By checking the final page using…

php:
var_dump($_SESSION);



I get…

array(3) {
["Step_1"]=>
string(1) "5"
["Step_2"]=>
string(8) "51,13,20"
["Step_3"]=>
string(3) "2,6"
}

Recordset:

php:
$ParamID_Recordset1 = "-1";

if (isset($_SESSION['Step_1'])) {
  $ParamID_Recordset1 = $_SESSION['Step_1'];
}
$ParamID_Recordset1 = "-1";
if (isset($_SESSION['Step_2'])) {
  $ParamID_Recordset1 = $_SESSION['Step_2'];
}
$ParamID_Recordset1 = "-1";
if (isset($_SESSION['Step_3'])) {
  $ParamID_Recordset1 = $_SESSION['Step_3'];
}
mysql_select_db($database_dbProducts, $dbProducts);
$query_Recordset1 = sprintf("SELECT ProductID FROM tblProducts WHERE ProductID = %s OR ProductID = %s OR ProductID = %s", GetSQLValueString($ParamID_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $dbProducts) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);


My results show only the first ID from each session, so obviously it's not looping through the entire session.
Do I need loop through all of the ids somehow? I figured the string in each session would do that?

Thanks,
TroyD

Sign in to reply to this post

Jason ByrnesWebAssist

you need to concatenate the 3 sessions into one, then use IN in your rrecordset:

http://www.w3schools.com/sql/sql_in.asp

Sign in to reply to this post

troyd

Jason,

Thanks. That's what I was needing.
I'm mot sure if my use of ternary operators in the concatenation is correct but it is working.( I need the ternary operators for something else I am trying to work on.)

Here is what I ended up with.

php:
<?php

session_start
();
$id[] = ($_SESSION['Step_1'] >= $_SESSION['Step_1'] : '') . "," . ($_SESSION['Step_2'] >= $_SESSION['Step_2'] : '') . "," . ($_SESSION['Step_3'] >= $_SESSION['Step_3'] : '');
foreach (
$id as $key => $pid){
}
?>



Recordset:

php:
SELECT ProductID FROM tblProducts WHERE ProductID IN ($pid)



Thanks,
TroyD

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