where "="

10 posts by 4 authors in: Forums > CMS Builder
Last Post: October 2, 2009   (RSS)

By s2smedia - September 30, 2009

Im trying to filter records for one section depending on what the user selects for a certain field. The options for the field they can select are pulling from another section.

For example..

The page lists Projects (Projects has its own section)
When you create a project you can select a Project Manager (the project manager options list pulls from the Accounts section)

So on the Projects page
I need it to display projects where "Mr. X" is the Project Manager

Here is the code I have so far.. which needs tweaked:

<?php
require_once "admin/lib/viewer_functions.php";

list($projectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'projects',
'where' => " project_manager = '{$accounts['id']}' ",

));

?>

Re: [s2smedia] where "="

By s2smedia - September 30, 2009

I have a login where when a user logins in it takes them to a page that displays there name using this code:

<?php echo $fullname;?>

so how can I use that code to filter the projects.

so it would be where project_manager = <?php echo $fullname;?>;

Re: [s2smedia] where "="

By Kenny - September 30, 2009

Read through this post and see if it helps

http://www.interactivetools.com/forum/gforum.cgi?post=74121#74121

Re: [sagentic] where "="

By s2smedia - September 30, 2009

I entered this in my code:
<?php
require_once "admin/lib/viewer_functions.php";

list($projectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'projects',
'where' => "project_manager = {$accountid}",
));

?>
I Get this error:

Notice: Undefined variable: accountid in /hermes/bosweb/web255/b2559/ipw.s2smedia/frontdesk/myprojects.php on line 17 getRecords(projects) MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY dragSortOrder, project_status DESC' at line 2

Re: [s2smedia] where "="

By Chris - September 30, 2009

Hi s2smedia,


I have a login where when a user logins in it takes them to a page that displays there name using this code:

<?php echo $fullname;?>


I'm not sure how your login system works, but if it's supplying you with a global variable called $fullname, and that's what you want to match on, I don't see why you can't drop it into the WHERE clause:

'where' => " project_manager = '".mysql_escape($fullname)."' ",

If that doesn't work, you'll need to fill us in on a few more details surrounding how $fullname is getting set so we can figure out how to get the "num" for the account you want to filter by.

I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [chris] where "="

By s2smedia - October 1, 2009

Yes I do. I'll give that a try.

I'm assuming I would need to use that .mysql_escape?

Thanks

Re: [s2smedia] where "="

By Chris - October 1, 2009

mysql_escape() is defined by including viewer_functions.php. Are you missing the "require_once" line from your page?

Please post the PHP source code of your myprojects.php page (as an attachment would be best) and we'll see if we can get this sorted out. :)
All the best,
Chris

Re: [s2smedia] where "="

By Dave - October 1, 2009

Also, mysql_escape() is a newer function. If you are running an older CMS Builder version and don't want to upgrade you can replace that with mysql_real_escape_string() which is built into PHP.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] where "="

By s2smedia - October 2, 2009

worked thanks