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?