detect if number in url
5 posts by 2 authors in: Forums > CMS Builder
Last Post: June 7, 2011 (RSS)
By zaba - June 7, 2011
Hi I want to detect whether there is a number in the url so I can decide which query to execute.
if (thereisanumberinurl) {
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => whereRecordNumberInUrl(1),,
'limit' => '1',
));
$blogRecord = @$blogRecords[0]; // get first record
}
else {
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => 'date >= (NOW() - INTERVAL 6 MONTH)',
'limit' => '1',
));
$blogRecord = @$blogRecords[0]; // get first record
Re: [zaba] detect if number in url
By Jason - June 7, 2011
Hi,
You can use the getNumberFromEndOfUrl() function to check for a number. If there are none, it returns 0:
Hope this helps
You can use the getNumberFromEndOfUrl() function to check for a number. If there are none, it returns 0:
if (getNumberFromEndOfUrl()) {
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$blogRecord = @$blogRecords[0]; // get first record
}
else {
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => 'date >= (NOW() - INTERVAL 6 MONTH)',
'limit' => '1',
));
$blogRecord = @$blogRecords[0]; // get first record
}
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] detect if number in url
By zaba - June 7, 2011
Thanks Jason,
Had to do a sub routine cos 0 is still a number and it didn't work how I wanted it to...
this now works although the code is probably not that great
Had to do a sub routine cos 0 is still a number and it didn't work how I wanted it to...
this now works although the code is probably not that great
$num = getNumberFromEndOfUrl() ;
if ($num==0) {
$num='';
}
else {
$num = getNumberFromEndOfUrl();
}
if (!empty ($num)) {
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
'debugSql' => false,
));
$blogRecord = @$blogRecords[0];
}
else {
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => 'date >= (NOW() - INTERVAL 6 MONTH)',
'limit' => '1',
'debugSql' => false,
));
$blogRecord = @$blogRecords[0];
}
Re: [zaba] detect if number in url
By Jason - June 7, 2011
Hi,
Would this work better for you?
Hope this helps
Would this work better for you?
if (getNumberFromEndOfUrl() !== 0) {
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$blogRecord = @$blogRecords[0]; // get first record
}
else {
list($blogRecords, $blogMetaData) = getRecords(array(
'tableName' => 'blog',
'where' => 'date >= (NOW() - INTERVAL 6 MONTH)',
'limit' => '1',
));
$blogRecord = @$blogRecords[0]; // get first record
}
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/