Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6626497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:53:58+00:00 2026-05-25T21:53:58+00:00

I am having a little trouble with the following php statement: if (!userIsLoggedIn()) {

  • 0

I am having a little trouble with the following php statement:

if (!userIsLoggedIn()) {
    $prPrice = (empty($prPrice2)) ? $prPrice1 : $prPrice1;
} else {
    $prPrice = (empty($prPrice2)) ? $prPrice1 : $prPrice2;
}

Here is an example of two products:

product 1 -> price1 = 1.00
product 1 -> price2 = 0.00
product 2 -> price1 = 1.00
product 2 -> price2 = 0.80

If a user is not logged into our website (userIsLoggedIn function) Then they should only be able to see the product price1, regardless if product price2 exists or not.

On the other hand, When a user has logged into our website. Then they should be able to see price2 for products where it exists, or they will simply see price1.

Now the problem with me code, is this:

A user is not logged on, they see price1 regardless of whether an item has a price2 set or not.

When a user has logged in, they see price2 for items that have a price two, but this is the strange part, for items that do not have a price2, it simply displays 0, Where it should display price1.

Does anyone have any input as to why the mentioned code is producing this effect?

I can provide further code relating to the userIsLoggedIn function, on request.

Thank you to anyone that would like to help!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:53:58+00:00Added an answer on May 25, 2026 at 9:53 pm

    Your code looks fine to me. You could verify that the variables hold the value you expect by using var_dump().

    Also your code might be shortened like this. However if you have to check a lot of prices it’s probably not adviseable to execute userIsLoggedIn() in each check but instead save that result in a variable.

    $prPrice = ($prPrice2 != 0 && userIsLoggedIn()) ? $prPrice2 : $prPrice1;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a little bit of trouble implementing the following method while handling the
Hey basically just having a little trouble with the following, submitting a message from
I'm new to android programming and I'm having a little trouble with the following.
I'm having a little trouble using Hibernate with a char(6) column in Oracle. Here's
I am having a little trouble with my PHP LDAP login. My first bind
having a little trouble with a mapping for the following table setup currently: Shop
Hay, I'm having a little trouble. I have the following domain over at easily.co.uk
I'm having a little trouble making an SQL SERVER 2000 query. Here is my
I'm having a little trouble defining my question. Here's what I have. A mailto
I'm having a little trouble with making the following piece of code work. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.