liamloveslearning Posted January 9, 2010 Share Posted January 9, 2010 Hi everyone, the page im working on has an array of variable at the top... $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL, 'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME, 'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER, 'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE, 'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY, 'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT, 'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE, 'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW); I have written a statement to say if product_list_price is 0 dont display a buy now button.. case 'PRODUCT_LIST_BUY_NOW': $lc_align = 'center'; if ($define_list['PRODUCT_LIST_PRICE']== '0'){ //fix for call for price $lc_text = ' '; } else { $lc_text = osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $osC_Product->getKeyword() . '&' . osc_get_all_get_params(array('action')) . '&action=cart_add'), osc_draw_image_button('button_buy_now.gif', $osC_Language->get('button_buy_now'))) . ' '; } break; } However its not working, Im unsure if its because my IF statement is correct or not, Ive read a few tutorials on google regarding it and im sure all the above code is correct, Can anybody tell me if theres something wrong or if it may be another matter? Link to comment https://forums.phpfreaks.com/topic/187834-beginner-question-regarding-arrays/ Share on other sites More sharing options...
spfoonnewb Posted January 9, 2010 Share Posted January 9, 2010 The code looks fine. Did you define the constant PRODUCT_LIST_PRICE? Here is an example: <?php define("PRODUCT_LIST_PRICE", "0"); $define_list = array( 'PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL, 'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME, 'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER, 'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE, 'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY, 'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT, 'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE, 'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW ); $lc_align = 'center'; switch ("PRODUCT_LIST_BUY_NOW") { case 'PRODUCT_LIST_BUY_NOW': if ($define_list['PRODUCT_LIST_PRICE'] == '0') { $lc_text = 'a space'; } else { $lc_text = 'the button'; } break; } echo $lc_text; ?> Link to comment https://forums.phpfreaks.com/topic/187834-beginner-question-regarding-arrays/#findComment-991728 Share on other sites More sharing options...
liamloveslearning Posted January 9, 2010 Author Share Posted January 9, 2010 Hi spfoonnewb, I havent no, I thought I wouldnt need to with it begin within the array? Link to comment https://forums.phpfreaks.com/topic/187834-beginner-question-regarding-arrays/#findComment-991729 Share on other sites More sharing options...
spfoonnewb Posted January 9, 2010 Share Posted January 9, 2010 Everything has to be defined, even if its in an array. Are you getting these values out of a database? Link to comment https://forums.phpfreaks.com/topic/187834-beginner-question-regarding-arrays/#findComment-991742 Share on other sites More sharing options...
liamloveslearning Posted January 9, 2010 Author Share Posted January 9, 2010 Ahhh, and I presume so, its an osCommerce install on my friends machine im just trying to modify parts of it, I cant get my head around it at all. The page doesnt seem to have any requirements or anything tho, and nothing defined.. <?php /* $Id$ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2007 osCommerce This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License v2 (1991) as published by the Free Software Foundation. */ // create column list $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL, 'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME, 'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER, 'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE, 'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY, 'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT, 'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE, 'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW); asort($define_list); $column_list = array(); reset($define_list); while (list($key, $value) = each($define_list)) { if ($value > 0) $column_list[] = $key; } if ( ($Qlisting->numberOfRows() > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) { ?> <div class="listingPageLinks"> <span style="float: right;"><?php echo $Qlisting->getBatchPageLinks('page', osc_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span> <?php echo $Qlisting->getBatchTotalPages($osC_Language->get('result_set_number_of_products')); ?> </div> <?php } ?> <div> <?php if ($Qlisting->numberOfRows() > 0) { ?> <table border="0" width="100%" cellspacing="0" cellpadding="2"> <tr> <?php for ($col=0, $n=sizeof($column_list); $col<$n; $col++) { $lc_key = false; $lc_align = ''; switch ($column_list[$col]) { case 'PRODUCT_LIST_MODEL': $lc_text = $osC_Language->get('listing_model_heading'); $lc_key = 'model'; break; case 'PRODUCT_LIST_NAME': $lc_text = $osC_Language->get('listing_products_heading'); $lc_key = 'name'; break; case 'PRODUCT_LIST_MANUFACTURER': $lc_text = $osC_Language->get('listing_manufacturer_heading'); $lc_key = 'manufacturer'; break; case 'PRODUCT_LIST_PRICE': $lc_text = $osC_Language->get('listing_price_heading'); $lc_key = 'price'; $lc_align = 'right'; break; case 'PRODUCT_LIST_QUANTITY': $lc_text = $osC_Language->get('listing_quantity_heading'); $lc_key = 'quantity'; $lc_align = 'right'; break; case 'PRODUCT_LIST_WEIGHT': $lc_text = $osC_Language->get('listing_weight_heading'); $lc_key = 'weight'; $lc_align = 'right'; break; case 'PRODUCT_LIST_IMAGE': $lc_text = $osC_Language->get('listing_image_heading'); $lc_align = 'center'; break; case 'PRODUCT_LIST_BUY_NOW': $lc_text = $osC_Language->get('listing_buy_now_heading'); $lc_align = 'center'; break; } if ($lc_key !== false) { $lc_text = osc_create_sort_heading($lc_key, $lc_text); } echo ' <td align="' . $lc_align . '" class="productListing-heading"> ' . $lc_text . ' </td>' . "\n"; } ?> </tr> <?php $rows = 0; while ($Qlisting->next()) { $osC_Product = new osC_Product($Qlisting->valueInt('products_id')); $rows++; echo ' <tr class="' . ((($rows/2) == floor($rows/2)) ? 'productListing-even' : 'productListing-odd') . '">' . "\n"; for ($col=0, $n=sizeof($column_list); $col<$n; $col++) { $lc_align = ''; switch ($column_list[$col]) { case 'PRODUCT_LIST_MODEL': $lc_align = ''; $lc_text = ' ' . $osC_Product->getModel() . ' '; break; case 'PRODUCT_LIST_NAME': $lc_align = ''; if (isset($_GET['manufacturers'])) { $lc_text = osc_link_object(osc_href_link(FILENAME_PRODUCTS, $osC_Product->getKeyword() . '&manufacturers=' . $_GET['manufacturers']), $osC_Product->getTitle()); } else { $lc_text = ' ' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $osC_Product->getKeyword() . ($cPath ? '&cPath=' . $cPath : '')), $osC_Product->getTitle()) . ' '; } break; case 'PRODUCT_LIST_MANUFACTURER': $lc_align = ''; $lc_text = ' '; if ( $osC_Product->hasManufacturer() ) { $lc_text = ' ' . osc_link_object(osc_href_link(FILENAME_DEFAULT, 'manufacturers=' . $osC_Product->getManufacturerID()), $osC_Product->getManufacturer()) . ' '; } break; case 'PRODUCT_LIST_PRICE': $lc_align = 'right'; $lc_text = ' ' . $osC_Product->getPriceFormated() . ' '; break; case 'PRODUCT_LIST_QUANTITY': $lc_align = 'right'; $lc_text = ' ' . $osC_Product->getQuantity() . ' '; break; case 'PRODUCT_LIST_WEIGHT': $lc_align = 'right'; $lc_text = ' ' . $osC_Product->getWeight() . ' '; break; case 'PRODUCT_LIST_IMAGE': $lc_align = 'center'; if (isset($_GET['manufacturers'])) { $lc_text = osc_link_object(osc_href_link(FILENAME_PRODUCTS, $osC_Product->getKeyword() . '&manufacturers=' . $_GET['manufacturers']), $osC_Image->show($osC_Product->getImage(), $osC_Product->getTitle())); } else { $lc_text = ' ' . osc_link_object(osc_href_link(FILENAME_PRODUCTS, $osC_Product->getKeyword() . ($cPath ? '&cPath=' . $cPath : '')), $osC_Image->show($osC_Product->getImage(), $osC_Product->getTitle())) . ' '; } break; case 'PRODUCT_LIST_BUY_NOW': $lc_align = 'center'; if ($define_list['PRODUCT_LIST_PRICE']== '0'){ //fix for call for price $lc_text = ' '; } else { $lc_text = osc_link_object(osc_href_link(basename($_SERVER['SCRIPT_FILENAME']), $osC_Product->getKeyword() . '&' . osc_get_all_get_params(array('action')) . '&action=cart_add'), osc_draw_image_button('button_buy_now.gif', $osC_Language->get('button_buy_now'))) . ' '; } break; } echo ' <td ' . ((empty($lc_align) === false) ? 'align="' . $lc_align . '" ' : '') . 'class="productListing-data">' . $lc_text . '</td>' . "\n"; } echo ' </tr>' . "\n"; } ?> </table> <?php } else { echo $osC_Language->get('no_products_in_category'); } ?> </div> <?php if ( ($Qlisting->numberOfRows() > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) { ?> <div class="listingPageLinks"> <span style="float: right;"><?php echo $Qlisting->getBatchPageLinks('page', osc_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span> <?php echo $Qlisting->getBatchTotalPages($osC_Language->get('result_set_number_of_products')); ?> </div> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/187834-beginner-question-regarding-arrays/#findComment-991744 Share on other sites More sharing options...
liamloveslearning Posted January 9, 2010 Author Share Posted January 9, 2010 Looking back now, I think because theres no data being called, thats why my IF statement isnt working as it should? Link to comment https://forums.phpfreaks.com/topic/187834-beginner-question-regarding-arrays/#findComment-991745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.