HELP ! Link in filtered combo page

7 posts by 2 authors in: Forums > CMS Builder
Last Post: December 13, 2012   (RSS)

Hi Guys,

I have a combo page, that displays a search result (to show categories - ie "type")

eg. http://blakemachinery.com.au/products.php?type=25

The list view on the side shows all the items within that category - however, select the item and it links products.php?xxx which then shows all items in the list, not still within the selected "type". It's also not showing the correct product.

I've attached the viewers and the products.php files.


Cheers,

Tim (toledoh.com.au)
Also, how can I link to a specific product? For instance, on the home page (http://blakemachinery.com.au/index.php) I have featured items in the carousel...
Cheers,

Tim (toledoh.com.au)
Hi Tim,

The problem is that the two getRecords functions for the products are using the number in the URL to select a specific num value, and not a type when you view a products details.

I think I've found a way around this, and modified and re-uploaded the files to this post. In the products_005.php I've stored the num value and type value separately in the URL, you should see the change on line 70:

<li<?php if ($isSelected) { print " class='active'"; } ?>><a href="products.php?num=<?php echo $listRecord['num']; ?><?php echo (@$type)? "type=$type" : ''; ?>">

Then in the _globalviewers.php file I've set set search to false for the getRecords functions that pull the products, and added where statements that get the the type and num value separately. I've set it up so that if no num or type value in the URL then they use a default value of 1.

//If there is a num value in the URL, set it to the variable num, if not there isn't use 1 as the defualt value
$num = (@$_REQUEST['num'])? intval($_REQUEST['num']) : '1';

list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'loadUploads' => true,
'where' => "num = '$num'",
'allowSearch' => false,
'limit' => '1',
));
$detailRecord = @$productsRecords[0]; // get first record

// load list records from 'products'

//If there is a type value in the URL, set it to the variable type, if not there isn't use 1 as the defualt value
$type = (@$_REQUEST['type'])? intval($_REQUEST['type']) : '1';

list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => "type = '$type'",
'loadUploads' => true,
'allowSearch' => false,
));


Let me know if this doesn't work.

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com
OK - pretty much working now (the error was fixed by cut and pasting the file content, rather than using the file itself... strange)

However, the "type" selectors from the home pae, or in the top navigation currently link to something like http://blakemachinery.com.au/products.php?type=25 which used to display the first record - but now, I guess because the $num=1, it's not displaying the detail of the first record.

Is there a way to get $num to equal the first record in that category? if you know what I mean...
Cheers,

Tim (toledoh.com.au)
Hi Tim,

I've rearranged the _globalviewers file slightly and added one new statement:

//If there is a type value in the URL, set it to the variable type, if not there isn't use 1 as the defualt value
$type = (@$_REQUEST['type'])? intval($_REQUEST['type']) : '1';

list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'where' => "type = '$type'",
'loadUploads' => true,
'allowSearch' => false,
));

//If there is a num value in the URL, set it to the variable num, if not then get the first num value from the current menu list.
$num = (@$_REQUEST['num'])? intval($_REQUEST['num']) : intval(@$productsRecords[0]['num']);
//If ther wasn't a value for the menu list, then set the num value to 0.
if($num < 1){ $num = 1; }

list($detailRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'loadUploads' => true,
'where' => "num = '$num'",
'allowSearch' => false,
'limit' => '1',
));
$detailRecord = @$detailRecords[0]; // get first record


So now if there isn't a num value in the URL, it tries to set it to the first num value in the $productsRecord array. If $productsRecord array is empty, then the $num variable is set to 1 as a last resort.

The updated version of globalviewers is attached to this post.

Thanks!

Greg
Greg Thomas







PHP Programmer - interactivetools.com
Attachments:

_globalviewers_002.php 3K

Brilliant... couldn't be better!

Thanks Greg!
Cheers,

Tim (toledoh.com.au)