Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

Help with $_session[points]

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Watch

noswad

Established Member
Impact
1
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!
 
Last edited:
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Something like this?

PHP:
<?php

session_start();

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

?>

And no need for the NP$ ;)
 
0
Close
Instead of $_SESSION['points'] == '', I would use !isset($_SESSION['points'])
 
0
Close
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
");

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 :'(​
 
0
Close
PHP:
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]));
 
0
Close
Thanks v much! :hehe:
 
Last edited:
0
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back