NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Help with $_session[points]

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-17-2006, 07:13 PM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Aug 2005
Location: Leeds, UK
Posts: 263
noswad is an unknown quantity at this point
 



Help with $_session[points]


Hi.

I have a page using sessions to obtain data from my database.

For example -

session_start();
echo("Your balance is $_SESSION[points] ");


So if a user has 10 points, it will display 'Your balance is 10'.

If the session picks up nothing in the database (I mean an empty field, not 0 points) is there a script I can implement so that the page doesnt display an empty line.

Thanks for reading and I will donate all my NP$ to any one who finds a solution!
__________________
Michael McIntyre - Fan site for the super funny UK comedian Michael McIntyre
Last edited by noswad; 05-17-2006 at 07:17 PM.
noswad is offline  
Old 05-17-2006, 07:17 PM   #2 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Something like this?

PHP Code:
<?php

session_start
();

if(
$_SESSION['points'] == '')
????: NamePros.com http://www.namepros.com/programming/198398-help-with-_session-points.html
{
  echo 
'';
}
else
{
  echo 
'Your balance is '.$_SESSION['points'];
}

?>
And no need for the NP$
Eric is offline  
Old 05-17-2006, 08:01 PM   #3 (permalink)
NamePros Regular
 
Jim_'s Avatar
Join Date: Aug 2005
Location: NY, USA
Posts: 610
Jim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to behold
 


Save The Children
Instead of $_SESSION['points'] == '', I would use !isset($_SESSION['points'])
__________________
ask me about the internet
Jim_ is offline  
Old 05-17-2006, 08:41 PM THREAD STARTER               #4 (permalink)
NamePros Regular
Join Date: Aug 2005
Location: Leeds, UK
Posts: 263
noswad is an unknown quantity at this point
 



Thanks for the replies. I think I may need to adapt on what I originally posted.

Basically, in the example below, if the field in the database for the session 'used' is empty I want 'Points Left:' to move up one line on the web page.

session_start();
echo("Points: $_SESSION[points] ");
session_start();
echo("Used: $_SESSION[used] ");
session_start();
echo("Points Left: $_SESSION[left] ");

At the moment, because the session 'used' is empty my page is displaying like this:

Points: 3

Points Left: 3

Where as I want it to display like this:

Points: 3
Points Left:3

And then when the user finally uses 1 point, I will update the databse so that the page auto displays like this:

Points: 3
Points Used: 1
Points Left: 2

Thanks again and sorry for not been clear initially
__________________
Michael McIntyre - Fan site for the super funny UK comedian Michael McIntyre
noswad is offline  
Old 05-17-2006, 08:44 PM   #5 (permalink)
NamePros Regular
 
Jim_'s Avatar
Join Date: Aug 2005
Location: NY, USA
Posts: 610
Jim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to behold
 


Save The Children
PHP Code:
session_start();
????: NamePros.com http://www.namepros.com/showthread.php?t=198398
echo 
"Points: "str_replace("\n","",str_replace("\r","",$_SESSION[points]));
echo 
"Used: "str_replace("\n","",str_replace("\r","",$_SESSION[used]));
echo 
"Points Left: "str_replace("\n","",str_replace("\r","",$_SESSION[left])); 
__________________
ask me about the internet
Jim_ is offline  
Old 05-17-2006, 09:22 PM THREAD STARTER               #6 (permalink)
NamePros Regular
Join Date: Aug 2005
Location: Leeds, UK
Posts: 263
noswad is an unknown quantity at this point
 



Thanks v much!
__________________
Michael McIntyre - Fan site for the super funny UK comedian Michael McIntyre
Last edited by noswad; 05-17-2006 at 09:26 PM.
noswad is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 11:28 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger