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

  • SEARCH
  • Home
  • 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 7028257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:21:49+00:00 2026-05-28T00:21:49+00:00

I am creating a directory listing, and am struggling with directing a php if

  • 0

I am creating a directory listing, and am struggling with directing a php if statement to trigger on the right event.

The statement controls the displaying of two paragraphs.

It looks like this:

if ($userIsLoggedIn && $_SESSION['accountNum'] == $lstId)
{   
    $pageContent .= "
    <span class='editListing'><a href='/listings/edit/basic/index.php'>Edit Listing...</a></span>
";
} else {
$pageContent .= "
    <span class='editListing'>Your Listing? <a href='/listings/edit/basic/index.php'>Login to edit...</a></span>
";
}

$userIsLoggedIn is a function that checks to see if a user had logged into the website. (When a user logs into the website, their account number is then stored as a session variable.)

The variable $lstId can be explained like this:

while ($row = mysql_fetch_array($data)) {
$lstId = $row['id'];
...

Where is it the value of the field id of any specific row that is stored within a mysql table.

Now, say a user searchs a string that returns 2 results. Each result is held within a container, and the loop causes the container to repeat, with each row result that is found as a match.

Inside of the container, is where the if statement comes into effect.

What i basically want to do, is for each listing, the user is prompted with “Your listing? Log in to edit” And if the user selects this link, they are directed to the login page, once logged in they are able to edit the listing that correlates to their user account.

But the problem i am having, is that $lstId seems to be any id of any row that is returned, so that basically, when a user logs into the website, the paragraph “edit listing” is displayed in each and every contained result, even the ones that do not relate to their account. If the user clicks this link, they are directed to a page where they can edit their own listing.

The effect i am aiming for, is that the paragraph “edit listing” will only appear in the result that contains their own listing. And in every other listing the paragraph will remain as “your listing, log in to edit”.

Here is the html in full that is used to generate each result:

if ($tempVar == 0) {
    $pageContent .= "
    <div class='searchResultS'>
    ";
    if ($total_pgs > 1)
    {
        $pageContent .= "
        <p>$paginator</p>
        ";
    }
}

$pageContent .= "
        <div class='searchResult'>
            <div class='searchResultWrapper'>
";

                if ($lstPage !== "")
                {   
                    $pageContent .= "
                        <span class='moreDetails'><a href='/listings/$lstPage.php'>More Details...</a></span>
                    ";
                }

$pageContent .= "
                    <h3>$lstName</h3>
 ";

                if ($userIsLoggedIn && $_SESSION['accountNum'] == $lstId)
                {   
                    $pageContent .= "
                        <span class='editListing'><a href='/listings/edit/basic/index.php'>Edit Listing...</a></span>
                    ";
                } else {
                    $pageContent .= "
                        <span class='editListing'>Your Listing? <a href='/listings/edit/basic/index.php'>Login to edit...</a></span>
                    ";
                }

$pageContent .= "
                <br style='clear:both; height:0; font-size: 1px; line-height: 0px;' />
                <div class='bizDesc'>
                    <p><span class='listHeadings'>Description:</span>  $lstDesc</p>
                </div>
                <div class='bizAddr'>
                    <p><span class='listHeadings'>Street:</span>  $lstAddress</p>
                    <p><span class='listHeadings'>Town:</span>  $lstArea</p>
                    <p><span class='listHeadings'>Province:</span>  $lstProvince</p>
                    <p><span class='listHeadings'>Post Code:</span>  $lstPostcode</p>
                    <p><span class='listHeadings'>GPS Co-Ords:</span>  $lstGps</p>
                </div>
                <div class='bizCont'>
                    <p><span class='listHeadings'>Contact:</span>  $lstContact</p>
                    <p><span class='listHeadings'>Tel:</span>  $lstTel</p>
                    <p><span class='listHeadings'>Cell:</span>  $lstCell</p>
                    <p><span class='listHeadings'>Fax:</span>  $lstFax</p>
                    <p><span class='listHeadings'>Skype:</span>  $lstSkype</p>
                    <p><span class='listHeadings'>eMail:</span>  <a href='mailto: $lstEmail?subject=Your listing on bergbiz.co.za'>$lstEmail</a></p>
                </div>
            </div>
        </div><!-- end .searchResult -->
";
$tempVar ++;
}

If anyone has any input, suggestions or insight regarding this, it would be greatly appreciated if you could share some of it with me!!

Thank you!

EDIT:

Code placed directly after the if statement within the loop:

$td = $_SESSION['accountNum'];
echo"session var is $td";
echo"lst id is $lstId";

Output:

session var is 10005lst id is 10003session var is 10005lst id is 10004session var is 10005lst id is 10002session var is 10005lst id is 10005

Any ideas why it is coming out like this? the session var stays the same, but the id variable is being looped?

  • 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-28T00:21:49+00:00Added an answer on May 28, 2026 at 12:21 am

    The first thing I’d note is that your if statement is using = and not ==, so it would return true for any $lstId. See if changing this:

    $_SESSION['accountNum'] = $lstId
    

    to this:

    $_SESSION['accountNum'] == $lstId
    

    doesn’t fix the immediate issue.

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

Sidebar

Related Questions

I am creating a directory of sorts with members and their profiles. I'm using
I'm creating a gem which has several scripts in the bin directory the utility
I am creating an application were I need to scan a directory hive to
When creating gems, I often have a directory structure like this: |--lib |-- helpers.rb
I'm write installer for my web site. Installer creating application pool, virtual directory and
Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select
Creating hashes of hashes in Ruby allows for convenient two (or more) dimensional lookups.
I'm creating a tar file from a directory as such /home/user/bla/mydir/ Now I want
I'm creating a directory on a specified location and then I'm trying to access
I am creating virtual directory in IIS 6 using C#. I am able to

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.