MySQL Query Question

6 posts by 2 authors in: Forums > CMS Builder
Last Post: June 16, 2011   (RSS)

Re: [gkornbluth] MySQL Query Question

By zip222 - June 16, 2011

I just did something like this on another site. I think this should work:

<?php
$where="WHERE createdByUserNum='".$CURRENT_USER['num']."'";
?>
SELECT num, title
FROM <?php echo $TABLE_PREFIX ?>event_titles
<?php echo $where ?>


something to consider, this approach will prevent everyone, including admin users, from having full access to the event_titles in that list. there is a way around this, but it is a little more complicated.

Re: [zip222] MySQL Query Question

By gkornbluth - June 16, 2011

Thanks Zip222,

I'll plug that in and give it a try.

As to the admins...

Good point.

Could I somehow add something like this (probably not correct syntax)?

orWhere $CURRENT_USER['isAdmin'] = 1
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] MySQL Query Question

By zip222 - June 16, 2011

I think this should work...

<?php
if ($CURRENT_USER['isAdmin'] {
$where="";
}
else {
$where="WHERE createdByUserNum='".$CURRENT_USER['num']."'";
}
?>


I just recently learned this technique and it can be incredibly useful.

Re: [zip222] MySQL Query Question

By gkornbluth - June 16, 2011

Thank you again.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [zip222] MySQL Query Question

By gkornbluth - June 16, 2011

After a bit of playing around, this is the final that works in case anyone else can benefit from it.

[code

]SELECT title, title
FROM <?php echo $TABLE_PREFIX ?>event_titles_silver
<?php if (!$CURRENT_USER['isAdmin']): ?>
<?php $where="WHERE createdByUserNum='".$CURRENT_USER['num']."'"; ?>
<?php echo $where ?>
<?php endif ?>
Thanks again zip222,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php