[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 05-17-2006, 06:13 PM   #1 (permalink)
NamePros Regular
 
Join Date: Aug 2005
Location: Leeds, UK
Posts: 260
70.00 NP$ (Donate)

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!
__________________
C905 - Sony Ericsson mobile phone with an 8 megapixel camera!

Last edited by noswad; 05-17-2006 at 06:17 PM.
noswad is offline  
Old 05-17-2006, 06:17 PM   #2 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Something like this?

PHP Code:
<?php

session_start
();

if(
$_SESSION['points'] == '')
{
  echo
'';
}
else
{
  echo
'Your balance is '.$_SESSION['points'];
}

?>
And no need for the NP$
__________________
Eric is offline  
Old 05-17-2006, 07:01 PM   #3 (permalink)
NamePros Regular
 
Jim_'s Avatar
 
Join Date: Aug 2005
Posts: 585
285.40 NP$ (Donate)

Jim_ is a name known to allJim_ is a name known to allJim_ is a name known to allJim_ is a name known to allJim_ is a name known to allJim_ is a name known to all

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, 07:41 PM   #4 (permalink)
NamePros Regular
 
Join Date: Aug 2005
Location: Leeds, UK
Posts: 260
70.00 NP$ (Donate)

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
__________________
C905 - Sony Ericsson mobile phone with an 8 megapixel camera!
noswad is offline  
Old 05-17-2006, 07:44 PM   #5 (permalink)
NamePros Regular
 
Jim_'s Avatar
 
Join Date: Aug 2005
Posts: 585
285.40 NP$ (Donate)

Jim_ is a name known to allJim_ is a name known to allJim_ is a name known to allJim_ is a name known to allJim_ is a name known to allJim_ is a name known to all

Save The Children
PHP Code:
session_start();
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, 08:22 PM   #6 (permalink)
NamePros Regular
 
Join Date: Aug 2005
Location: Leeds, UK
Posts: 260
70.00 NP$ (Donate)

noswad is an unknown quantity at this point


Thanks v much!
__________________
C905 - Sony Ericsson mobile phone with an 8 megapixel camera!

Last edited by noswad; 05-17-2006 at 08:26 PM.
noswad is offline  
Closed Thread


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

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 07:21 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85