Products Page and Paypal

12 posts by 2 authors in: Forums > CMS Builder
Last Post: February 25, 2008   (RSS)

By Djulia - February 13, 2008 - edited: February 16, 2008

Hello,

I would like to create a Array, but I encounter a problem.

I have a section Shop and I would like to obtain the list of the products in a table (Array).

Here the structure of my section :

Shop :
Product1 : item_name, item_number, amount, ...
Product2 : item_name, item_number, amount, ...

Shop == Section Name
ProductXX == Page
item_xx == Field

Now, I would like to obtain a page (catolog.php) with the articles in tables (Array) :
<?PHP

$items = array(
array(
'item_name' => 'Product1',
'item_number' => 'sw01',
'amount' => '30.50',
'on0' => 'Delivery',
'os0' => 'Instant download',
'on1' => 'Option Name',
'os1' => 'Option Value',
'file' => '/home/domain/files/test_software.zip',
),
array(
'item_name' => 'Product2',
'item_number' => 'song02',
'amount' => '0.50',
'on0' => 'Delivery',
'os0' => 'Instant download',
'on1' => 'Format',
'os1' => 'MP3',
'file' => '/home/domain/file.mp3',
),
);

?>

I do not see how to obtain this.

Thank you for your assistance.

Djulia

Re: [Djulia] Catalogs Page

By Dave - February 13, 2008

So this is for some custom PHP coding your doing?

I think if you take a look at $listRows, it's in the exact format you're looking for. Try this:

<xmp><?php print_r($listRows); ?></xmp>

Does that help?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Catalogs Page

By Djulia - February 14, 2008

Thank you Dave for your assistance. [:)]

In fact, I try to use a Cart-based system to process orders Paypal. The system gives the possibility to use dynamic PHP code to create the list of items from a database.

Items in the catalog.php file are stored in a PHP array format called $items which is an array of associative arrays.
http://www.stellarwebsolutions.com/en/products.php#evendorpro

Also, your solution is correct. But I still have a problem and I do not know if the origin is the table created or script. I await an answer of the editor.

If not, it is possible to obtain a array with only some entries ?

Currently, I obtain :

Array
(
[0] => Array
(
[num] => 1
[item_number] => sw01
[amount] => 30
[item_name] => Test Software Widget
[_link] => /paypal/productsPage.php/1/
)...




I could obtain :

Array
(
[0] => Array
(
[item_number] => sw01
[amount] => 30
[item_name] => Test Software Widget
)...




It is perhaps the origin of my problem.
Thank you for your answer.

Djulia

Re: [Dave] Catalogs Page

By Djulia - February 21, 2008 - edited: February 21, 2008

Hi Dave,

I have a new challenge for CMS Builder.

I would like to add several elements at the end of my table (array) with the function array_push.

I tested : [blush]

<?php
require_once "/home/../lib/viewer_functions.php";
$options = array_push[/#ff0000]();
$options['tableName'] = 'products';
...
?>

But that gives an error message :
Warning: Wrong parameter count for array_push() in /home/../myPage.php on line xx

An example of what I must obtain :

section 1
<?PHP

$items = array (

array (
'item_name' => 'Cotton T-Shirt',
'item_number' => 'on1',
'amount' => '9.50',
));?>



section 2
<?PHP array_push ($items,

array (
'item_name' => 'Shirt',
'item_number' => 'os8',
'amount' => '19.99',
));
?>

where array == section 1
and array_push == section 2
...

You think that there is a solution ?

Thank you for your assistance.

Djulia

Re: [Djulia] Catalogs Page

By Dave - February 21, 2008

Hi Djulia,

I think you probably want to add those to $listRows, or some other variable and not $options?

Is that right? If so you'd do it after the line where you define $listRows but before you list it.

Does that make sense?
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Catalogs Page

By Djulia - February 22, 2008 - edited: February 22, 2008

Thank you Dave for your answer.

In fact, I am lost a little.

I tested in catalog.php :

<?php
require_once "/home/../lib/viewer_functions.php";
$options = array();
$options['tableName'] = 'products1';
$options['perPage'] = '9999';
$options['where'] = '1';
list($items1, $listDetails) = getListRows($options);
?>


<?php
require_once "/home/../lib/viewer_functions.php";
$options = array();
$options['tableName'] = 'products2';
$options['perPage'] = '9999';
$options['where'] = '1';
list($items2, $listDetails) = getListRows($options);
?>

<?php
$stack = array_push($items1, $items2);
?>

<xmp><?php print_r($stack); ?></xmp>



But, that gives the correct number of the recordings, but does not give the table.

You have an idea ?

Thank you for your assistance.

Djulia

Re: [Dave] Catalogs Page

By Djulia - February 22, 2008

I obtained the table, but that does not correspond to my need.

<?php
$stack = array_push($items1, $items2);
$items = $items1;
?>

The result gives a new table in the table.

Array
(
[0] => Array
(
[num] => 1
[item_number] => R02
[amount] => 29.99
...
)

[1] => Array
(
[num] => 2
[item_number] => R01
[amount] => 19.99
...
)

...

[4] => Array
(
[0] => Array
(
[num] => 1
[item_number] => P1
[item_name] => P1
[amount] => 10
...
)


)

)




You think that it is possible to have only one table ?

Array
(
[0] => Array
(
[num] => 1
[item_number] => R02
[amount] => 29.99
...
)

[1] => Array
(
[num] => 2
[item_number] => R01
[amount] => 19.99
...
)

...

[4] => Array
(
[num] => 1
[item_number] => P1
[item_name] => P1
[amount] => 10
...
)
)




Thank you for your assistance.

Djulia

Re: [Djulia] Catalogs Page

By Dave - February 22, 2008

Hi Djulia,

array_push() pushes a reference (or pointer) to $items2 on the end of $item1. Try array_merge(). I think that will do what you want.

<?php
$stack = array_merge($items1, $items2);
?>


See these links for more details:
http://www.php.net/array_merge
http://www.php.net/array_push

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

Re: [Dave] Catalogs Page

By Djulia - February 23, 2008 - edited: February 23, 2008

Thank you Dave for your assistance,

Your solution is correct, but it does not function with script.

In fact, the script functions with 2 catalog files :

// include the product catalog file in cart.php
require_once ('catalog1.php');
require_once ('catalog2.php');

The array (items, declared in catalog1.php) is built with these 2 files and the function array_push used in the file catalog2.php.

The code that I currently use in catalog2.php is : <?php
require_once "/home/.../lib/viewer_functions.php";
$options['tableName'] = 'products';
$options['perPage'] = '9999';
$options['where'] = '1';
list($pr) = getListRows($options);
array_push($items, $pr);
?>

And, it gives me 2 arrays :

<?PHP
array_push ($items, array(
array(
'item_name' => 'Product1',
'item_number' => 'pr_01',
'amount' => '19.99',
)
));
?>

But, I only need 1 array :

<?PHP
array_push ($items,
array(
'item_name' => 'Product1',
'item_number' => 'pr_01',
'amount' => '19.99',
)
);
?>

I tested :

<?php
require_once "/home/.../lib/viewer_functions.php";
$options['tableName'] = 'products';
$options['perPage'] = '9999';
$options['where'] = '1';
list($pr_) = getListRows($options);
array_push($items, $options);
?>



That functions with the script, but does not give the good values.

It would be possible to use something like this :

array_push($items, getListRows($options));

You think that there is a solution ?

Thanks,

Djulia