session variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ak

    session variable

    Hello,

    I have following problem:
    I try to retrieve images from mysql and show it.
    I retrieve them in loop using getData.php.
    getData.php uses session variable ($_SESSION['num']) to get image.

    However $_SESSION['num'] seems to be always 0.
    why?

    //showAll.php
    <?php
    session_start() ;
    $num=0;
    session_registe r('num');
    ?>
    <html>
    <head><title>Sh ow data from SQL Database</title></head>
    <body>

    <?php
    MYSQL_CONNECT(" localhost","roo t","pw");
    mysql_select_db ("database") ;
    $sql = "SELECT count(id) FROM store;";
    $result = MYSQL_QUERY($sq l);
    $count = MYSQL_RESULT($r esult,0,"count( id)");

    //-------------------------------------------------------------------
    //here is loop where $_SESSION['num'] is set and getData.php called

    while($count >1) {
    $_SESSION['num']=$count--;
    echo $_SESSION['num'];
    ?>
    <IMG SRC="getData.ph p">
    <?php
    }
    //-------------------------------------------------------------------
    ?>
    </body>
    </html>


    //-------------------------------------------------------------------

    //getData.php
    <?php
    session_start() ;
    if(isset($_SESS ION['num'])) {

    @MYSQL_CONNECT( "localhost","ro ot","pw");

    @mysql_select_d b("database") ;

    $num=$_SESSION['num'];
    $query = "select FileData,filety pe from store where id=$num";
    $result = @MYSQL_QUERY($q uery);

    $data = @MYSQL_RESULT($ result,0,"FileD ata");
    $type = @MYSQL_RESULT($ result,0,"filet ype");

    Header( "Content-type: $type");
    echo $data;
    }
    ?>


  • Von Heler

    #2
    Re: session variable

    On 25 Aug 2004, much to the astonishment of all present at comp.lang.php,
    ak blurted:
    [color=blue]
    > Hello,
    >
    > I have following problem:
    > I try to retrieve images from mysql and show it.
    > I retrieve them in loop using getData.php.
    > getData.php uses session variable ($_SESSION['num']) to get image.
    >
    > However $_SESSION['num'] seems to be always 0.
    > why?
    >
    > //showAll.php
    > <?php
    > session_start() ;
    > $num=0;
    > session_registe r('num');
    > ?>
    > <html>
    > <head><title>Sh ow data from SQL Database</title></head>
    > <body>
    >
    > <?php
    > MYSQL_CONNECT(" localhost","roo t","pw");
    > mysql_select_db ("database") ;
    > $sql = "SELECT count(id) FROM store;";
    > $result = MYSQL_QUERY($sq l);
    > $count = MYSQL_RESULT($r esult,0,"count( id)");
    >
    > //-------------------------------------------------------------------
    > //here is loop where $_SESSION['num'] is set and getData.php called
    >
    > while($count >1) {
    > $_SESSION['num']=$count--;
    > echo $_SESSION['num'];
    > ?>
    > <IMG SRC="getData.ph p">
    > <?php
    > }
    > //-------------------------------------------------------------------
    > ?>
    > </body>
    > </html>
    >
    >
    > //-------------------------------------------------------------------
    >
    > //getData.php
    > <?php
    > session_start() ;
    > if(isset($_SESS ION['num'])) {
    >
    > @MYSQL_CONNECT( "localhost","ro ot","pw");
    >
    > @mysql_select_d b("database") ;
    >
    > $num=$_SESSION['num'];
    > $query = "select FileData,filety pe from store where id=$num";
    > $result = @MYSQL_QUERY($q uery);
    >
    > $data = @MYSQL_RESULT($ result,0,"FileD ata");
    > $type = @MYSQL_RESULT($ result,0,"filet ype");
    >
    > Header( "Content-type: $type");
    > echo $data;
    > }
    > ?>
    >
    >[/color]

    I don't know if you have to use the line $_SESSION['cart'][] = array();
    but this seemed to help me in a similar situation.

    if (!isset($_SESSI ON['count'])) {
    $_SESSION['count'] = 1;
    } else {
    $_SESSION['count']++;
    }


    $_SESSION['cart'][] = array();
    $_SESSION['cart'][$count] = $item;



    for ($n = 1; $n <= $count; $n++) {
    *******
    }

    Comment

    Working...