RE: Session Values Change

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jacob,

Here is my solution.
At the top, it checks to see if you are passing a new name via a querystring.  
If not, it checks to see if a name is present in the session yet.  If not, it initializes the session to "Jacob".  It puts the session's value into the variable $view.
If you passed a name, it stores the name in the session and has it in the variable $view.

Now, $view will have a name that the SQL statement can use.

At the bottom, where you choose a name, it simply passes the name selection back to the page via a querystring field.

Try the following (notice the changes at the top and the links around the names at the bottom):

 <?php
session_start();

$view = $_GET['view'];
if ($view == '')
{
	if (! isset($_SESSION['view'])) 
	{
		$_SESSION['view'] = "Jacob";
	}
	$view = $_SESSION['view'];
} else {
	$_SESSION['view'] = $view;
}
?>


 #FORMATTING CODE HERE
                     $dbuser='php' ;
                     $dbpass='';
                     $dbhost='localhost';
                   
                     $conn = mysql_connect ( $dbhost , $dbuser , $dbpass );
                     //mysql_select_db ( "web" );
                     $sql = 'Select UNIX_TIMESTAMP(date) AS
date,title,article from web.blog where user="'.$view.'" order by date desc
LIMIT 10';
                     $result = mysql_query($sql);
                        //Execute For Future Use: SELECT
DATE_FORMAT(date,'%W, %D %M, %Y %l:%i%p') content FROM blog
                   
                      while ( $dataRow = mysql_fetch_row ( $result ) ) {
                   
                         $date=date("F dS Y h:i:s A", $dataRow[0]);
                   
                      echo '<a name="'.$date.'"></a>';
                      echo '  <div class="date">'.$date. '</div>';
                      echo '  <h3>'.$dataRow[1].'</h3>';
                      echo '  <p>'.$dataRow[2].'</p><br>';
                      #echo $sql ;
                      }
                      mysql_close ( $conn );

#FORMATTING CODE HERE

   <div id="footer">
                <p>
                    Other Users:
                <br>
                    <a href="pagename.php?view=Jacob">Jacob Hackamack</a> | <a href="pagename.php?view=Julie">Julie Hackamack</a> | <a href="pagename.php?view=David">David Hackamack</a></p>
            </div>

-----Original Message-----
From: Jacob Hackamack [mailto:JHackamack@xxxxxxxxxx]
Sent: Tuesday, July 27, 2004 10:21 PM
To: php-db@xxxxxxxxxxxxx
Subject: Session Values Change


Hello,  

I am trying to start a blog page where the person selects their person they
want to view (bottom of the page) and then it somehow changes the session
variable (top of the code) and then accesses the database.  I was wondering,
what is the correct way to do something like this.  I have tried a couple of
options (a hrefs) but they didn¹t seem to work and was wondering if anybody
had any suggestions.

Thank You In Advance

Jacob


<?php
session_start();

if (! isset($_SESSION['view']))
    {
   $_SESSION['view'] = "Jacob";
}

?>


 #FORMATTING CODE HERE
                     $dbuser='php' ;
                     $dbpass='';
                     $dbhost='localhost';
                   
                     $conn = mysql_connect ( $dbhost , $dbuser , $dbpass );
                     //mysql_select_db ( "web" );
                     $sql = 'Select UNIX_TIMESTAMP(date) AS
date,title,article from web.blog where user="'.$view.'" order by date desc
LIMIT 10';
                     $result = mysql_query($sql);
                        //Execute For Future Use: SELECT
DATE_FORMAT(date,'%W, %D %M, %Y %l:%i%p') content FROM blog
                   
                      while ( $dataRow = mysql_fetch_row ( $result ) ) {
                   
                         $date=date("F dS Y h:i:s A", $dataRow[0]);
                   
                      echo '<a name="'.$date.'"></a>';
                      echo '  <div class="date">'.$date. '</div>';
                      echo '  <h3>'.$dataRow[1].'</h3>';
                      echo '  <p>'.$dataRow[2].'</p><br>';
                      #echo $sql ;
                      }
                      mysql_close ( $conn );

#FORMATTING CODE HERE

   <div id="footer">
                <p>
                    Other Users:
                <br>
                    Jacob Hackamack | Julie Hackamack | David Hackamack</p>
            </div>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux