Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts

    discarding IDs (in sessions) for query ?

    Hey,

    Whats the best way to build sessions so that I can use it to cancel out the "site_ids" the user has already came from or been too.

    with something like this in sql query
    PHP Code:
    AND trade_sites.site_id NOT IN (".$site_ids."

    -this doesnt seem to work the way I thought it would
    PHP Code:
    $sitenumbers $_SESSION['log_visited'];
    if(
    $sitenumbers) { $site_ids implode(", "$sitenumbers); }
     return 
    $site_ids
    log_visited are set like " , 103, 547, 210, 215 " just throws in all the ids. I need a way to log and track Id's so that it doesnt repeat it in the query. If someone could help me on a good modification that could organize the ids to place in the query using sessions?

    Thanks
    Last edited by sitNsmile; 04-26-2010 at 08:21 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You're treating a string as an array, if the log_visited has the format of " , 103, 547, 210, 215 ", it is a string. You then try to implode it together, which will not work.
    Its the right idea, but the log_visited is the incorrect datatype. When you add to it, use $_SESSION['log_visited'][] = 'site_id'; instead of appending with a $_SESSION['log_visited'] .= ', site_id';. This will allow you to use an implode and not worry about the proper formatting of the string (which can become damaged should you start removing from it).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    I tried to do something like this, such as building an array, but for some reason i'm still getting blank when I added in the "NOT IN (siteid) - in query for some reason.

    This is what is putting into the session that I want to extract from and build a list of "site_ids"
    PHP Code:
    $plugs_visited $_SESSION['sites_visited'].",".$SiteId;
            
    $_SESSION['sites_visited'] = $plugs_visited;
            
    $print_v $_SESSION['sites_visited'];

            
    $split explode(','$print_v);

            while(list(
    $key,$value) = each($split))
            {
                
    $pluggedcontent[]=$value;
            }

            
    $pluggedcontent array_unique($pluggedcontent);
            
    //$clean_array = array_shift($pluggedcontent);

            
    $_SESSION['log_visited'] = $pluggedcontent

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I'm not sure why you're using a string at all, or the sites_visited. All you need is the log_visited:
    PHP Code:
    // Adding $SiteId to the log_visited
    if (!isset($_SESSION['log_visited']) || !is_array($_SESSION['log_visited']))
    {
        
    $_SESSION['log_visited'] = array();
    }

    if (!
    in_array($SiteId$_SESSION['log_visited']))
    {
        
    $_SESSION['log_visited'][] = $SiteId;
    }

    // Then when building your SQL
    $currentSQLStuff .= ' AND trade_sites.site_id NOT IN (' implode(', '$_SESSION['log_visited']) . ')'
    Assuming that log_visited are lists of numbers and trade_sites.site_id is an numerical field (preferably a numerical primary key or unique/indexed field).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    sitNsmile (04-26-2010)

  • #5
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts

    Thumbs up

    Quote Originally Posted by Fou-Lu View Post
    I'm not sure why you're using a string at all, or the sites_visited. All you need is the log_visited:
    PHP Code:
    // Adding $SiteId to the log_visited
    if (!isset($_SESSION['log_visited']) || !is_array($_SESSION['log_visited']))
    {
        
    $_SESSION['log_visited'] = array();
    }

    if (!
    in_array($SiteId$_SESSION['log_visited']))
    {
        
    $_SESSION['log_visited'][] = $SiteId;
    }

    // Then when building your SQL
    $currentSQLStuff .= ' AND trade_sites.site_id NOT IN (' implode(', '$_SESSION['log_visited']) . ')'
    Assuming that log_visited are lists of numbers and trade_sites.site_id is an numerical field (preferably a numerical primary key or unique/indexed field).
    Yeah, Awesome Thank you. That worked perfectly. Once again Fou-Lu!

  • #6
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts

    question

    Actually question for you Fou-Lu

    When I add in

    PHP Code:
    $currentSQLStuff .= ' AND trade_sites.site_id NOT IN (' implode(', '$_SESSION['log_visited']) . ')'
    in query. and say if session log_visited is empty because that person hasnt gone anywhere. Why would the query come out to null/blank. If I put something in the session, the query works. But need it to work both ways.

    any ideas why it would say nothing if the NOT IN is also blank?

    - so actually to fix that all I did was
    PHP Code:
    if (!$checkone){$checkone=0;} 
    but still, is that only quick fix to something like that?

    Thanks
    Last edited by sitNsmile; 04-26-2010 at 08:34 PM.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Simple solution:
    PHP Code:
    if (!empty($_SESSION['log_visited']))
    {
        
    // Then when building your SQL 
        
    $currentSQLStuff .= ' AND trade_sites.site_id NOT IN (' implode(', '$_SESSION['log_visited']) . ')';  

    That way it will only append the AND ... NOT IN (...) if your log_visited has at least one entry.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #8
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    358
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Fou-Lu View Post
    Simple solution:
    PHP Code:
    if (!empty($_SESSION['log_visited']))
    {
        
    // Then when building your SQL 
        
    $currentSQLStuff .= ' AND trade_sites.site_id NOT IN (' implode(', '$_SESSION['log_visited']) . ')';  

    That way it will only append the AND ... NOT IN (...) if your log_visited has at least one entry.

    ah yea thats true. I thought of that before hand, but I wasn't sure if it was the way I wanted to build the query. Guess cant hurt.

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Definitely not the only way, but its a pretty easy way
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •