Unstoppable Domains

Help with $_session[points]

Spaceship Spaceship
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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
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
•••
Instead of $_SESSION['points'] == '', I would use !isset($_SESSION['points'])
 
0
•••
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
•••
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
•••
Thanks v much! :hehe:
 
Last edited:
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back