LIST ONLY RECORDS WHERE CURRENT USER IS AUTHOR - Jul 24th, 2011


On a membership site the client wanted to display only those records that were authored by the current user from a table
called "subscription_pages".

The first step was to limit the records returned to only those where the Current user was the Author with a where clause
in the get records call:



list($subscription_pagesRecords, $subscription_pagesMetaData) = getRecords(array(
'tableName' => 'subscription_pages',
'where' => 'createdByUserNum = "'. $CURRENT_USER['num'] .'"' ,


));


Then for an added touch, I welcomed the user by name and added their subscription level to the greeting.



Welcome <?php echo mysql_escape($CURRENT_USER['first_name']); ?> <?php echo mysql_escape($CURRENT_USER['last_name']);
?>, <?php if ($CURRENT_USER['allowedFolders'] == "entry_level"): ?>Entry<?PHP endif ?><?php if
(
$CURRENT_USER['allowedFolders'] == "silver"): ?>Silver<?PHP endif ?><?php if ($CURRENT_USER['allowedFolders'] ==
"gold"): ?>Gold<?PHP endif ?><?php if ($CURRENT_USER['allowedFolders'] == "platinum"): ?>Platinum<?PHP endif ?> level
subscriber.


Then where I wanted to display the user's choices:



<?php foreach ($subscription_pagesRecords as $record): ?>
<?php if ($record['createdByUserNum']== @$CURRENT_USER['num']): ?>

<!-- Records Created By User #: <?php echo $record['createdByUserNum'] ?> Exist - Current User is # : <?php echo
@
$CURRENT_USER['num'] ?><br />-->

<span class="medium">TO VIEW ALL OF YOUR LISTINGS - </span><a href="master_listing.php"><span
class="medium"><u><b>CLICK HERE</b></u></span></a>
<br /> <br />
<span class="medium">TO ADD LISTINGS OR MODIFY EXISTING LISTINGS - </span><a href="cmsAdmin/admin.php"><span
class="medium"><u><b>CLICK HERE</b></u></span></a>
<br /> <br />
<?php endif ?><?php break ; ?><?php endforeach ?>


And if the current user had not created any records:



<?php if (!$subscription_pagesRecords): ?>
<span class="medium">YOU HAVEN'T CREATED ANY LISTINGS YET. </span><a
href="http://96.0.19.10/cmsAdmin/admin.php"><span class="medium"><u><b>CLICK HERE</b></u></span></a>
<span class="medium">TO GET STARTED.</span>
<br /> <br />
<?php endif ?>




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service