Jump to content

Recommended Posts

Hi,

 

I got a scenario to where I've hard coded the login (user name & password) that will be used by multiple locations to access a database to query and print out inventory lables (that part coded and all queries working without issue).

 

Problem: I need a method to where I can store (each individual entity's) select data - i.e. productss 1,2,3,4,5, etc... for that particular session - and once all selected records confirmed <by that specified user>, loop through that saved data to print out that data accordingly.

 

My issue (that's giving me trouble coming up w/design):

1. I have to use the 'hard-coded' global login which will be assigned to all locations <creating unique logins not possible>

2. There are 400 to 500 products and the objectives is to allow each user - remember, they all will have the exact same username & password which reason I can't distinguish between them - to search and select the ones they need printed out - labels. Therefore, I need to save each search (results) temporarily until that user advise, "NO additioinal searches required" adding to array or table - at that point, it should loop back through the saved data and print out to a page.

 

Note: Being there will only be one GENERAL login that will be used by all, I currently don't see how I can manage this with MySQL - being MySQL really  not required to save the data b/c soon as they print the selected info, it's no longer required. For this reason, I was thinking about temporary tables are PHP Sessions but not sure if either suitable for this setup.

 

If I could save each user's session as that - a session - sending each (form submission) to s session's array to later loop through it to query final set of data to print out it out then kill that session, that would be perfect. Problem is I haven't been able to figure out the logic /code.

 

EXAMPLE:

$product_id = 1;     // this would be the results 1st search that I need saved (temporarily until the final loop on that saved array queried for print function)
$product_id = 4;     // this would be results of 2nd search
$product_id = 8      // this would be results of 3rd search, etc... until they click "NO" to stop returning to search form.

 

At that point, that's when I need to query the $product[] array or session - looping through it to retrive all the saved product_ids as shown above...

 

I thought doing something like:

 

$products[] = $_REQUEST['product_id'];               // for the 1st loop
$_SESSION['products'] = $products;                     // then create a session to save that info before returning to the search form for another query

// then for later subbsions, there would be IF/Else check to know the session exist so simply add new element to end of existing array
array_push($_SESSION['products'], $products_id);

 

Can anyone advise and possibly provide and example or either?

For the temp tables, I'm not sure this would work b/c if multiple locations (users) start building a search at same time, they may cancel one another out.

 

Sort of stumped on this one but I know there is a way to save the data (hopefully in a session) to later loop through that session to print info out?

Note: I only need to save the record id as they search through database and once they click (no more searches), that's when I then need to loop through the saed array to SELECT each record's specific info to print each out accordingly.

SESSION data is unique per client (browser.) Each session gets a unique session id, that the browser provides with each request it makes to the server. The name `session' is derived from 'browser session'.

So is it possible I can use that 'unique' session id - per user/location - and on the SQL INSERT, include that variable to save the data to a record (updating it accordingly until no more additions)? Then query the database - based on the session id to pull that record back up - with all the saved fields, to query each of those individual records to print?

 

I'll probably need to save that session_id as a different variable so I can delete that entire database record once the print task is complete - to save disk space.

Note: I understand the theory about a session; need a possible solution / design but thanks for response.

Also, one user (session) may loop through the search form three to four hundred times - selecting 300 to 400 unique product id's to which I'll then need to query to pull each product's info to print each accordingly. This is why i need to figure out a way to save each form search / query (per user) to complete the final query.

 

Note: the reason i have to do it this way is b/c they will be entering sku #'s in a text field so it will repeat each time they need to perform a new search.

Got it?

You are way over thinking this. You are basically making a session based 'cart', where the items in the cart are product id's that you are going to print labels for.

 

You would just store the searched for id's as array entries under a specifically named session variable. In general, you would use the product id as a key of an array, so that you can, if needed, store and access specific information using that key, such as a quantity or an array of product information.

 

<?php
// add to session -
$key = 123; // some product id
$_SESSION['cart'][$key] = true; // using true just as a flag, you can assign any other value, such as maintaining a quantity or even an array of values.

 

You can either loop over the $_SESSION['cart'] array or you can use array_keys($_SESSION['cart']) to get just the ids.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.