where/filter records using URL string

28 posts by 3 authors in: Forums > CMS Builder
Last Post: August 17, 2010   (RSS)

By s2smedia - August 13, 2010

I have a site set up that is basically 1 pg website shell... then depending what member/user you are..

ex:
http://www.clubambassadors.org/pages/index.php?num=2
http://www.clubambassadors.org/pages/index.php?num=3

it displays different content...

my issue is the way I have it above now limits only CONTENT that is num=3 to display..

somehow need something in the URL to say display records from table_name, num=3 and table_name, CreatedbyUsernum=5

Re: [s2smedia] where/filter records using URL string

By Chris - August 13, 2010

Hi s2smedia,

How about something like this?

$where = '';
if (@$_REQUEST['num']) {
mysql_escapef('num = ?', @$_REQUEST['num']);
}
else {
mysql_escapef('createdByUserNum = ?', @$_REQUEST['createdByUserNum']);
}

list($theRecords, $theMetaData) = getRecords(array(
'tableName' => @$_REQUEST['table_name'],
'where' => $where,
));
$theRecord = @$theRecords[0]; // get first record

// show error message if no matching record is found
if (!$theRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}


Is that how you wanted CreatedbyUsernum=5 to work? To display the first record with CreatedbyUsernum=5? Or did you want the page to turn into a list page if that's supplied?

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

Re: [chris] where/filter records using URL string

By s2smedia - August 13, 2010

that looks almost right... :)

I would mainly need all lists of all records by that userNum

not just 1 records

Re: [s2smedia] where/filter records using URL string

By Chris - August 13, 2010

Hi s2smedia,

I think you might be better off with a different page if one use case displays a single record while a different use case lists multiple records. That said it would still be possible to do this. Please post the complete PHP source code for your page and I'll show you how.
All the best,
Chris

Re: [chris] where/filter records using URL string

By s2smedia - August 13, 2010

There's only one not listed as a list. But I can certainly make all setup as a list and do it that way

Re: [s2smedia] where/filter records using URL string

By s2smedia - August 13, 2010

I will post code

Re: [s2smedia] where/filter records using URL string

By s2smedia - August 13, 2010

I just noticed if I type:

http://clubambassadors.org/pages/index.php?club_name=CASL


it displays everything correctly except now just needs to on display records (news, events...etc) created by num

the above club_name=CASL is record 3

Re: [s2smedia] where/filter records using URL string

By Chris - August 16, 2010 - edited: August 16, 2010

Hi s2smedia,

Oh! I misunderstood you earlier.

How about this:

<?php


// load viewer library
$libraryPath = 'login/lib/viewer_functions.php';
$dirsToCheck = array('XXX');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'where' => mysql_escapef('num = ?', @$_REQUEST['owner']),
'limit' => '1',
));
$accountsRecord = @$accountsRecords[0]; // get first record

// load records
list($eventsRecords, $eventsMetaData) = getRecords(array(
'tableName' => 'events',
'where' => mysql_escapef('createdByUserNum = ?', @$_REQUEST['owner']),
));

// load records
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'perPage' => '4',
'where' => mysql_escapef('createdByUserNum = ?', @$_REQUEST['owner']),
));

// load records
list($banner_managerRecords, $banner_managerMetaData) = getRecords(array(
'tableName' => 'banner_manager',
'limit' => '2',
'orderBy' => 'RAND()',
));

?>


Then you can create URLs like this: index.php?owner=3

Does this help? Please let me know if you have any questions.
All the best,
Chris

Re: [chris] where/filter records using URL string

By s2smedia - August 16, 2010

makes sense.. but im getting this error:

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' at line 3