LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2004, 02:19 AM   #1
vikaspa
LQ Newbie
 
Registered: Mar 2004
Posts: 1

Rep: Reputation: 0
php session array : What's wrong in this code


Dear ALL

PLEASE HELP


I am trying to accumulate values in an array.

I am happy with the value stored in variable page_views

However the array defines is initialised...

May be I had not defined properly

Can any one help me to store valued in session array....

May be (rather certainly) there is an error..

Thanks in advance
Vikas Athavale

<?php
session_start();
session_register("page_views");
session_register("arv");

$arv=array();

$k=count($_session["arv"]);
$k++;
echo "<br> count= ".$k."<br>";
$_session["arv"] [$k]= $page_views;

echo "<br>value stored in session var arrayvariable = ".$_session["arv"] [$k] ."<br>";
$page_views++;

echo "<br> _session count= ".count($avar)."<br>";

echo "You have viewed this page ";
echo $page_views;
echo " times(s).";

?>
 
Old 03-29-2004, 10:15 AM   #2
elitecodex
Member
 
Registered: Feb 2004
Location: MD
Distribution: Fedora 9
Posts: 129

Rep: Reputation: 15
If im understanding it, looks to me that everytime you declare $arv=array(); you are essentially wiping out the old data with an empty array.

Try testing for it being equal to null before declaring it as an empty array... no need to declare it if its already stored in a session.
 
Old 03-30-2004, 08:37 AM   #3
Ohmu
LQ Newbie
 
Registered: Jan 2004
Location: Estonia
Distribution: Gentoo
Posts: 20

Rep: Reputation: 0
The biggest mistake in your code is that you are tring to access global variables the wrong way.. all the global variables are with capitalized letters, like: $_GET, $_POST, $_SESSION, $_COOKIES, $_SERVER, etc..

Note: $arv isn't the same as $_SESSION['arv']

And at:
PHP Code:
$_SESSION["arv"][$k]= $page_views
You haven't set the $page_views so you assign empty value for $_SESSION["arv"][$k]

Hopefully you understand me
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Are PHP session variables held in memory when you leave a PHP site? Locura Programming 11 11-16-2008 08:37 PM
array of unions (c code) alaios Programming 6 09-16-2005 11:43 AM
PHP something wrong with the code :( Alexander.s Programming 2 04-22-2005 04:27 AM
Only 1 choice as x-session-manager alternatives, but it's the wrong one. wartstew Debian 7 09-19-2004 08:00 PM
php array gui10 Programming 2 03-26-2002 02:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration