Looking at a piece of code at the moment and trying to work out how to set a minimum order price of £10 within this code. I want the 'Confirm your order' CTA to be inactive unless the order is £10 - Or maybe upon selecting the CTA, no action, just a message to display saying the order should be £10 or over when the CTA is selected.
Any help would be great, I have a huge headache from this. I've been trying to learn to code but I am in way over my head with this one.
<?php
use mp_restaurant_menu\classes\models;
use mp_restaurant_menu\classes\View;
/**
* #return mixed
*/
function mprm_is_checkout() {
return models\Checkout::get_instance()->is_checkout();
}
/**
* #return mixed
*/
function mprm_get_checkout_uri() {
return models\Checkout::get_instance()->get_checkout_uri();
}
function mprm_get_checkout_cart_template() {
$data = array();
$data[ 'is_ajax_disabled' ] = models\Settings::get_instance()->is_ajax_disabled();
$data[ 'cart_items' ] = models\Cart::get_instance()->get_cart_contents();
mprm_get_template('shop/checkout-cart', $data);
}
/**
* #return mixed
*/
function mprm_checkout_button_next() {
$color = mprm_get_option('checkout_color', 'mprm-btn blue');
$color = ($color == 'inherit') ? '' : $color;
$padding = mprm_get_option('checkout_padding', 'mprm-inherit');
$style = mprm_get_option('button_style', 'button');
$purchase_page = mprm_get_option('purchase_page', '0');
ob_start();
?>
<input type="hidden" name="mprm_action" value="gateway_select"/>
<input type="hidden" name="page_id" value="<?php echo absint($purchase_page); ?>"/>
<input type="submit" name="gateway_submit" id="mprm_next_button" class="mprm-submit <?php echo $color; ?> <?php echo $padding; ?> <?php echo $style; ?>" value="<?php _e('Next', 'mp-restaurant-menu'); ?>"/>
<?php
return apply_filters('mprm_checkout_button_next', ob_get_clean());
}
/**
* Checkout purchase button
* #return mixed
*/
function mprm_checkout_button_purchase() {
$color = mprm_get_option('checkout_color', 'mprm-btn blue');
$color = ($color == 'inherit') ? '' : $color;
$style = mprm_get_option('button_style', 'button');
$label = mprm_get_option('checkout_label', '');
$padding = mprm_get_option('checkout_padding', 'mprm-inherit');
if (mprm_get_cart_total()) {
$complete_purchase = !empty($label) ? $label : __('Purchase', 'mp-restaurant-menu');
} else {
$complete_purchase = !empty($label) ? $label : __('Free Menu item', 'mp-restaurant-menu');
}
ob_start();
?>
<input type="submit" class="mprm-submit <?php echo $color; ?> <?php echo $padding; ?> <?php echo $style; ?>" id="mprm-purchase-button" name="mprm-purchase" value="<?php echo $complete_purchase; ?>"/>
<?php
return apply_filters('mprm_checkout_button_purchase', ob_get_clean());
}
/**
* #return bool
*/
function mprm_is_no_guest_checkout() {
return models\Misc::get_instance()->no_guest_checkout();
}
function mprm_checkout_tax_fields() {
if (models\Taxes::get_instance()->cart_needs_tax_address_fields() && mprm_get_cart_total()) {
mprm_default_cc_address_fields();
}
}
function mprm_checkout_submit() { ?>
<fieldset id="mprm_purchase_submit">
<?php do_action('mprm_purchase_form_before_submit'); ?>
<?php mprm_checkout_hidden_fields(); ?>
<?php echo mprm_checkout_button_purchase(); ?>
<?php do_action('mprm_purchase_form_after_submit'); ?>
</fieldset>
<?php
}
function mprm_checkout_additional_information() {
View::get_instance()->get_template('/shop/checkout-additional-information');
}
function mprm_checkout_final_total() {
?>
<p id="mprm_final_total_wrap">
<strong><?php _e('Total:', 'mp-restaurant-menu'); ?></strong>
<span class="mprm_cart_amount" data-subtotal="<?php echo mprm_get_cart_subtotal(); ?>" data-total="<?php echo mprm_get_cart_subtotal(); ?>"><?php echo mprm_currency_filter(mprm_format_amount(mprm_get_cart_total())); ?></span>
</p>
<?php
}
function mprm_checkout_hidden_fields() {
?>
<?php if (is_user_logged_in()) { ?>
<input type="hidden" name="mprm-user-id" value="<?php echo get_current_user_id(); ?>"/>
<?php } ?>
<input type="hidden" name="mprm_action" value="purchase"/>
<input type="hidden" name="controller" value="cart"/>
<input type="hidden" name="mprm-gateway" value="<?php echo models\Gateways::get_instance()->get_chosen_gateway(); ?>"/>
<?php
}
/**
* Delivery address default
*/
function mprm_checkout_delivery_address() {
if (mprm_get_option('shipping_address')): ?>
<p id="mprm-address-wrap">
<label for="shipping_address" class="mprm-label">
<?php _e('Shipping address:', 'mp-restaurant-menu'); ?>
</label>
<input type="text" name="shipping_address" value="" class="medium-text" placeholder="<?php _e('Enter your address.', 'mp-restaurant-menu'); ?>"/>
</p>
<?php endif;
}
/**
* Checkout order notes
*/
function mprm_checkout_order_note() {
?>
<p id="mprm-phone-number-wrap">
<label for="customer_note" class="mprm-label">
<?php _e('Order notes:', 'mp-restaurant-menu'); ?>
</label>
<textarea type="text" name="customer_note" id="customer_note" class="phone-number mprm-input"></textarea>
</p>
<?php }
/**
* Summary table
*/
function mprm_checkout_summary_table() { ?>
<span class="mprm-payment-details-label"><legend><?php _e('Order totals', 'mp-restaurant-menu'); ?></legend></span>
<table class="mprm-table">
<?php do_action('mprm_checkout_table_subtotal_before'); ?>
<tr>
<td class=""><span><?php _e('Subtotal', 'mp-restaurant-menu'); ?> </span></td>
<td><span class="mprm_cart_subtotal_amount"><?php echo mprm_currency_filter(mprm_format_amount(mprm_get_cart_subtotal())) ?></span></td>
</tr>
<?php do_action('mprm_checkout_table_subtotal_after'); ?>
<?php do_action('mprm_checkout_table_tax_before'); ?>
<?php if (mprm_use_taxes()) : ?>
<tr <?php if (!mprm_is_cart_taxed()) echo ' style="display:none;"'; ?>>
<td><span><?php _e('Tax', 'mp-restaurant-menu'); ?></span></td>
<td><span class="mprm_cart_tax_amount" data-tax="<?php echo mprm_get_cart_tax(); ?>"><?php echo mprm_currency_filter(mprm_format_amount(mprm_get_cart_tax())) ?></span></td>
</tr>
<?php endif; ?>
<?php do_action('mprm_checkout_table_tax_after'); ?>
<?php do_action('mprm_checkout_table_total_before'); ?>
<tr class="mprm-checkout-total">
<td>
<span><b><?php _e('Total', 'mp-restaurant-menu'); ?></b></span>
</td>
<td><span class="mprm_cart_amount"><b><?php echo mprm_currency_filter(mprm_format_amount(mprm_get_cart_total())) ?></b></span></td>
</tr>
<?php do_action('mprm_checkout_table_total_after'); ?>
</table>
<?php }
/**
* Send to success page
*
* #param string $query_string
*/
function mprm_send_to_success_page($query_string) {
return models\Checkout::get_instance()->send_to_success_page($query_string);
}
/**
* Send back to checkout
*
* #param $args
*/
function mprm_send_back_to_checkout($args) {
return models\Checkout::get_instance()->send_back_to_checkout($args);
}
Related
I'm a noob when it comes to PHP.
However, my employer is asking me to hide the "Add To Cart" button for products in certain categories. I'm wondering if any of you could take a look and help me solve the problem
I appreciate any help you may be able to offer. Unfortunately this task is above my head and the other answers on this don't clearly specify what I need to change.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// #codingStandardsIgnoreFile
/** #var $block \Magento\Catalog\Block\Product\View */
?>
<?php
$helper = $this->helper("Lof\RequestForQuote\Helper\Data");
$enable = $helper->isEnabledQuote();
$disable_qty = $helper->getConfig('general/disable_qty');
$disable_qty = ($disable_qty !==null)?(int)$disable_qty:0;
$disable_addtocart = $helper->getConfig('general/disable_addtocart');
$disable_addtocart = ($disable_addtocart !==null)?(int)$disable_addtocart:0;
$enable_addtoquote = $helper->getConfig('general/enable_addtoquote');
$enable_addtoquote = ($enable_addtoquote !==null)?(int)$enable_addtoquote:1;
?>
<?php $_product = $block->getProduct(); ?>
<?php if ($enable && $disable_addtocart && ($enable_addtoquote || ($_product->hasData('product_quote') && $_product->getData('product_quote')))) {
?>
<div class="box-tocart">
<div class="fieldset">
<?php if ($block->shouldRenderQuantity() && !$disable_qty): ?>
<div class="field qty">
<label class="label" for="qty"><span><?= /* #escapeNotVerified */ __('Qty') ?></span></label>
<div class="control">
<input type="number"
name="qty"
id="qty"
value="<?= /* #escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>"
title="<?= /* #escapeNotVerified */ __('Qty') ?>"
class="input-text qty"
data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
/>
</div>
</div>
<?php endif; ?>
<div class="actions">
<?= $block->getChildHtml('', true) ?>
</div>
</div>
</div>
<?php if ($block->isRedirectToCartEnabled()) : ?>
<script type="text/x-magento-init">
{
"#product_addtocart_form": {
"Magento_Catalog/product/view/validation": {
"radioCheckboxClosest": ".nested"
}
}
}
</script>
<?php else : ?>
<script type="text/x-magento-init">
{
"#product_addtocart_form": {
"Magento_Catalog/js/validate-product": {}
}
}
</script>
<?php endif; ?>
<?php
} else { ?>
<?php $buttonTitle = __('Add to Cart'); ?>
<?php if ($_product->isSaleable()): ?>
<div class="box-tocart">
<div class="fieldset">
<?php if ($block->shouldRenderQuantity()): ?>
<div class="field qty">
<label class="label" for="qty"><span><?= /* #escapeNotVerified */ __('Qty') ?></span></label>
<div class="control">
<input type="number"
name="qty"
id="qty"
value="<?= /* #escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>"
title="<?= /* #escapeNotVerified */ __('Qty') ?>"
class="input-text qty"
data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
/>
</div>
</div>
<?php endif; ?>
<div class="actions">
<button type="submit"
title="<?= /* #escapeNotVerified */ $buttonTitle ?>"
class="action primary tocart"
id="product-addtocart-button">
<span><?= /* #escapeNotVerified */ $buttonTitle ?></span>
</button>
<?= $block->getChildHtml('', true) ?>
</div>
</div>
</div>
<?php endif; ?>
<?php if ($block->isRedirectToCartEnabled()) : ?>
<script type="text/x-magento-init">
{
"#product_addtocart_form": {
"Magento_Catalog/product/view/validation": {
"radioCheckboxClosest": ".nested"
}
}
}
</script>
<?php else : ?>
<script type="text/x-magento-init">
{
"#product_addtocart_form": {
"Magento_Catalog/js/validate-product": {}
}
}
</script>
<?php endif; ?>
<?php } ?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I am getting this error
Parse error: syntax error, unexpected 'endforeach' (T_ENDFOREACH),
expecting elseif (T_ELSEIF) or else (T_ELSE) or endif (T_ENDIF) in
/var/www/html/app/design/frontend/nego/nego_default/Magento_Catalog/templates/product/list.phtml
on line 130
list.phtml shows this:
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\App\Action\Action;
// #codingStandardsIgnoreFile
?>
<?php
/**
* Product list template
*
* #var $block \Magento\Catalog\Block\Product\ListProduct
*/
?>
<?php
$_productCollection = $block->getLoadedProductCollection();
$_helper = $this->helper('Magento\Catalog\Helper\Output');
?>
<?php if (!$_productCollection->count()): ?>
<div class="message info empty"><div><?php /* #escapeNotVerified */ echo __('We can\'t find products matching the selection.') ?></div></div>
<?php else: ?>
<?php echo $block->getToolbarHtml() ?>
<?php echo $block->getAdditionalHtml() ?>
<?php
if ($block->getMode() == 'grid') {
$viewMode = 'grid';
$image = 'category_page_grid';
$showDescription = false;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
} else {
$viewMode = 'list';
$image = 'category_page_list';
$showDescription = true;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::FULL_VIEW;
}
/**
* Position for actions regarding image size changing in vde if needed
*/
$pos = $block->getPositioned();
?>
<div class="products wrapper <?php /* #escapeNotVerified */ echo $viewMode; ?> products-<?php /* #escapeNotVerified */ echo $viewMode; ?>">
<?php $iterator = 1; ?>
<ol class="products list items product-items">
<?php /** #var $_product \Magento\Catalog\Model\Product */ ?>
<?php foreach ($_productCollection as $_product): ?>
<?php /* #escapeNotVerified */ echo($iterator++ == 1) ? '<li class="item product product-item">' : '</li><li class="item product product-item">' ?>
<div class="product-item-info" data-container="product-grid">
<div class=" product-item-images">
<?php
$newFromDate = $_product->getNewsFromDate();
$newToDate = $_product->getNewsToDate();
$now = date("Y-m-d H:m:s");
// Get the Special Price
$specialprice = $_product->getSpecialPrice();
// Get the Special Price FROM date
$specialPriceFromDate = $_product->getSpecialFromDate();
// Get the Special Price TO date
$specialPriceToDate = $_product->getSpecialToDate();
// Get Current date
if ($specialprice&&(($specialPriceFromDate <= $now && $specialPriceToDate >= $now) || (($specialPriceFromDate <= $now && $specialPriceFromDate != NULL) && $specialPriceToDate == ''))){
$_savePercent = 100 - round(($_product->getSpecialPrice() / $_product->getPrice())*100);
echo "<span class='hot-sale'>-".$_savePercent."%</span>";
}else{
if((($newFromDate <= $now && $newToDate >= $now) || (($newFromDate <= $now && $newFromDate != NULL) && $newToDate == NULL))) {
?>
<div class="label-pro-new"><span><?php echo __('new!') ?></span></div>
<?php
}
}
?>
<?php
$productImage = $block->getImage($_product, $image);
if ($pos != null) {
$position = ' style="left:' . $productImage->getWidth() . 'px;'
. 'top:' . $productImage->getHeight() . 'px;"';
}
?>
<?php // Product Image ?>
<a href="<?php /* #escapeNotVerified */ echo $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
<?php echo $productImage->toHtml(); ?>
</a>
</div>
<div class="product-item-details">
<?php
$_productNameStripped = $block->stripTags($_product->getName(), null, true);
?>
<strong class="product name product-item-name">
<a class="product-item-link"
href="<?php /* #escapeNotVerified */ echo $_product->getProductUrl() ?>">
<?php /* #escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
</a>
</strong>
<?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
<?php /* #escapeNotVerified */ echo $block->getProductPrice($_product) ?>
<?php echo $block->getProductDetailsHtml($_product); ?>
<?php if ($showDescription):?>
<div class="product description product-item-description">
<?php /* #escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
<a href="<?php /* #escapeNotVerified */ echo $_product->getProductUrl() ?>" title="<?php /* #escapeNotVerified */ echo $_productNameStripped ?>"
class="action more"><?php /* #escapeNotVerified */ echo __('Learn More') ?></a>
</div>
<?php endif; ?>
<div class="product-item-actions"<?php echo strpos($pos, $viewMode . '-actions') ? $position : ''; ?>>
<div class="add-to-cart-primary"<?php echo strpos($pos, $viewMode . '-primary') ? $position : ''; ?>>
<?php if ($_product->isSaleable()): ?>
<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form" action="<?php /* #escapeNotVerified */ echo $postParams['action']; ?>" method="post">
<input type="hidden" name="product" value="<?php /* #escapeNotVerified */ echo $postParams['data']['product']; ?>">
<input type="hidden" name="<?php /* #escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* #escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
<?php echo $block->getBlockHtml('formkey')?>
<button type="submit"
title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
class="tocart">
<span><?php /* #escapeNotVerified */ echo __('Add to Cart') ?></span>
</button>
</form>
</div>
</div>
</div>
</div>
<?php echo($iterator == count($_productCollection)+1) ? '</li>' : '' ?>
<?php endforeach; ?>
</ol>
</div>
<?php echo $block->getToolbarHtml() ?>
<?php if (!$block->isRedirectToCartEnabled()) : ?>
<script type="text/x-magento-init">
{
"[data-role=tocart-form], .form.map.checkout": {
"catalogAddToCart": {}
}
}
</script>
<?php endif; ?>
<?php endif; ?>
All other pages works. But the category pages shows error.
You didn't close "if" statement started in line 111. Just add it after line 123.
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\App\Action\Action;
// #codingStandardsIgnoreFile
?>
<?php
/**
* Product list template
*
* #var $block \Magento\Catalog\Block\Product\ListProduct
*/
?>
<?php
$_productCollection = $block->getLoadedProductCollection();
$_helper = $this->helper('Magento\Catalog\Helper\Output');
?>
<?php if (!$_productCollection->count()): ?>
<div class="message info empty"><div><?php /* #escapeNotVerified */ echo __('We can\'t find products matching the selection.') ?></div></div>
<?php else: ?>
<?php echo $block->getToolbarHtml() ?>
<?php echo $block->getAdditionalHtml() ?>
<?php
if ($block->getMode() == 'grid') {
$viewMode = 'grid';
$image = 'category_page_grid';
$showDescription = false;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
} else {
$viewMode = 'list';
$image = 'category_page_list';
$showDescription = true;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::FULL_VIEW;
}
/**
* Position for actions regarding image size changing in vde if needed
*/
$pos = $block->getPositioned();
?>
<div class="products wrapper <?php /* #escapeNotVerified */ echo $viewMode; ?> products-<?php /* #escapeNotVerified */ echo $viewMode; ?>">
<?php $iterator = 1; ?>
<ol class="products list items product-items">
<?php /** #var $_product \Magento\Catalog\Model\Product */ ?>
<?php foreach ($_productCollection as $_product): ?>
<?php /* #escapeNotVerified */ echo($iterator++ == 1) ? '<li class="item product product-item">' : '</li><li class="item product product-item">' ?>
<div class="product-item-info" data-container="product-grid">
<div class=" product-item-images">
<?php
$newFromDate = $_product->getNewsFromDate();
$newToDate = $_product->getNewsToDate();
$now = date("Y-m-d H:m:s");
// Get the Special Price
$specialprice = $_product->getSpecialPrice();
// Get the Special Price FROM date
$specialPriceFromDate = $_product->getSpecialFromDate();
// Get the Special Price TO date
$specialPriceToDate = $_product->getSpecialToDate();
// Get Current date
if ($specialprice&&(($specialPriceFromDate <= $now && $specialPriceToDate >= $now) || (($specialPriceFromDate <= $now && $specialPriceFromDate != NULL) && $specialPriceToDate == ''))){
$_savePercent = 100 - round(($_product->getSpecialPrice() / $_product->getPrice())*100);
echo "<span class='hot-sale'>-".$_savePercent."%</span>";
}else{
if((($newFromDate <= $now && $newToDate >= $now) || (($newFromDate <= $now && $newFromDate != NULL) && $newToDate == NULL))) {
?>
<div class="label-pro-new"><span><?php echo __('new!') ?></span></div>
<?php
}
}
?>
<?php
$productImage = $block->getImage($_product, $image);
if ($pos != null) {
$position = ' style="left:' . $productImage->getWidth() . 'px;'
. 'top:' . $productImage->getHeight() . 'px;"';
}
?>
<?php // Product Image ?>
<a href="<?php /* #escapeNotVerified */ echo $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1">
<?php echo $productImage->toHtml(); ?>
</a>
</div>
<div class="product-item-details">
<?php
$_productNameStripped = $block->stripTags($_product->getName(), null, true);
?>
<strong class="product name product-item-name">
<a class="product-item-link"
href="<?php /* #escapeNotVerified */ echo $_product->getProductUrl() ?>">
<?php /* #escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
</a>
</strong>
<?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
<?php /* #escapeNotVerified */ echo $block->getProductPrice($_product) ?>
<?php echo $block->getProductDetailsHtml($_product); ?>
<?php if ($showDescription):?>
<div class="product description product-item-description">
<?php /* #escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
<a href="<?php /* #escapeNotVerified */ echo $_product->getProductUrl() ?>" title="<?php /* #escapeNotVerified */ echo $_productNameStripped ?>"
class="action more"><?php /* #escapeNotVerified */ echo __('Learn More') ?></a>
</div>
<?php endif; ?>
<div class="product-item-actions"<?php echo strpos($pos, $viewMode . '-actions') ? $position : ''; ?>>
<div class="add-to-cart-primary"<?php echo strpos($pos, $viewMode . '-primary') ? $position : ''; ?>>
<?php if ($_product->isSaleable()): ?>
<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form" action="<?php /* #escapeNotVerified */ echo $postParams['action']; ?>" method="post">
<input type="hidden" name="product" value="<?php /* #escapeNotVerified */ echo $postParams['data']['product']; ?>">
<input type="hidden" name="<?php /* #escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* #escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
<?php echo $block->getBlockHtml('formkey')?>
<button type="submit"
title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>"
class="tocart">
<span><?php /* #escapeNotVerified */ echo __('Add to Cart') ?></span>
</button>
</form>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php echo($iterator == count($_productCollection)+1) ? '</li>' : '' ?>
<?php endforeach; ?>
</ol>
</div>
<?php echo $block->getToolbarHtml() ?>
<?php if (!$block->isRedirectToCartEnabled()) : ?>
<script type="text/x-magento-init">
{
"[data-role=tocart-form], .form.map.checkout": {
"catalogAddToCart": {}
}
}
</script>
<?php endif; ?>
<?php endif; ?>
This is from an unsupported WordPress plugin that I'm trying to revive. I'm getting an error in the following code which states
Fatal Error class WP_Widget not found on Line 7
It works with PHP 5.3.3 but not on 5.6 or any version of PHP 7. Any suggestions would be appreciated.
<?php
/**
*
* Widget Class
*/
class Twitter_Like_Box_Widget extends WP_Widget
{
var $_options;
function __construct( ) {
global $tlb;
$this->wpb_prefix = $tlb->get_domain();
$widget_ops = array( 'classname' => 'tlb_widget', 'description' => ' Display your Twitter followers along with a follow me button' ); // Widget Settings
$control_ops = array( 'id_base' => 'tlb_widget' ); // Widget Control Settings
parent::__construct( 'tlb_widget', 'Twitter Like Box', $widget_ops, $control_ops );
$this->_options = $tlb->getOptions();
}
//Function to init the widget values and call the display widget function
function widget($args,$instance)
{
$title = apply_filters('widget_title', $instance['title']); // the widget title
$username = $instance['username']; // the widget title
$total_number = $instance['total_number']; // the number of followers to show
$show_followers = $instance['show_followers']; // show followers or users i follow
$link_followers = $instance['link_followers']; // link followers to profile
$width = $instance['width']; // link followers to profile
$widget = array ( 'username' => $username ,'total' => $total_number , 'show_followers' => $show_followers ,'link_followers'=> $link_followers, 'width' => $width, 'options' => $this->_options);
echo $args['before_widget'];
if ( $title )
echo $args['before_title'] . $title . $args['after_title'];
$this->display_widget($widget);
echo $args['after_widget'];
}
//function that display the widget form
function form($instance)
{
global $tlb;
$defaults = array( 'total_number' => 10, 'show_followers' => 'followers','link_followers'=> 'on','title' => 'My Followers', 'username' => 'chifliiiii');
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<?php if( $tlb->error != '' && defined('DOING_AJAX')):?>
<div class="error">
<p><?php echo sprintf(__('Check you OAuth settings, there is a problem with the connection.',$this->wpb_prefix),admin_url('options-general.php?page=twitter-like-box-reloaded'));?></p>
</div>
<?php endif;?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:',$this->wpb_prefix);?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>'" type="text" value="<?php echo $instance['title']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('username'); ?>"><?php _e('Username (without #):',$this->wpb_prefix);?></label>
<input class="widefat" id="<?php echo $this->get_field_id('username'); ?>" name="<?php echo $this->get_field_name('username'); ?>'" type="text" value="<?php echo $instance['username']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('show_thumbs'); ?>"><?php _e('Show Followers or people you follow?',$this->wpb_prefix);?></label>
</p>
<ul>
<li>
<input type="radio" class="radio" <?php checked( $instance['show_followers'], 'followers' ); ?> id="<?php echo $this->get_field_id('show_followers'); ?>" name="<?php echo $this->get_field_name('show_followers'); ?>" value="followers"/> <?php _e('Followers',$this->wpb_prefix);?>
</li>
<li>
<input type="radio" class="radio" <?php checked( $instance['show_followers'], 'nofollowers' ); ?> id="<?php echo $this->get_field_id('show_followers'); ?>" name="<?php echo $this->get_field_name('show_followers'); ?>" value="nofollowers" /> <?php _e('People I follow',$this->wpb_prefix);?>
</li>
</ul>
<p>
<label for="<?php echo $this->get_field_id('total_number'); ?>"><?php _e('How many you want to show?',$this->wpb_prefix); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('total_number'); ?>" name="<?php echo $this->get_field_name('total_number'); ?>" type="text" value="<?php echo $instance['total_number']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('link_followers'); ?>"><?php _e('Link followers to their profiles?',$this->wpb_prefix); ?></label>
<input type="checkbox" class="checkbox" <?php checked( $instance['link_followers'], 'on' ); ?> id="<?php echo $this->get_field_id('link_followers'); ?>" name="<?php echo $this->get_field_name('link_followers'); ?>" value="on" />
</p>
<p>
<label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Widget width:',$this->wpb_prefix); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width') ; ?>'" type="text" value="<?php echo isset($instance['width']) ? $instance['width'] : '100%'; ?>" />
</p>
<p>
<?php _e('More settings',$this->wpb_prefix);?>
</p>
<?php
}
//function that save the widget
function update($new_instance, $old_instance)
{
$instance['title'] = strip_tags($new_instance['title']);
$instance['username'] = strip_tags( $new_instance['username'] )== '' ? 'chifliiiii' : strip_tags( $new_instance['username'] );
$instance['total_number'] = strip_tags($new_instance['total_number']);
$instance['show_followers'] = $new_instance['show_followers'];
$instance['link_followers'] = $new_instance['link_followers'];
$instance['width'] = $new_instance['width'];
//Delete transient in case exist
$key = 'tlb_widgets_' . $instance['username'];
delete_transient($key);
return $instance;
}
//Finally thevfunction that create the widget
static function get_tlb_widget($widget)
{
global $tlb,$you;
$wpb_prefix = $tlb->get_domain();
$twitter = self::fetch_twitter_followers($widget);
ob_start();
if( !empty($you['error']) && '32' == $you['code']) {
echo $you['error'];
}
else
{
?>
<style type="text/css">
<?php echo $widget['options']['custom_css'];?>
</style>
<div id="tlb_container" style="width: <?php echo isset($widget['width']) ? $widget['width'] : 'auto';?>">
<?php if(isset($twitter['error']) ) :?>
<?php echo $twitter['error'];?>
<?php else : ?>
<div>
<div id="tlb_profile_img">
<a target="_blank" href="http://twitter.com/<?php echo $widget['username'];?>">
<img src="<?php echo $twitter['profile_image_url'];?>" width="44" height="44" align="left" alt="<?php echo $widget['username'];?>">
</a>
</div>
<div id="tlb_name">
<a target="_blank" href="http://twitter.com/<?php echo $widget['username'];?>">
<?php echo $widget['username'];?><span> <?php _e('on Twitter',$wpb_prefix);?></span>
</a>
</div>
<div id="tlb_follow">
<?php _e('Follow #',$wpb_prefix);?><?php echo $widget['username'];?>
</div>
</div><br>
<div style="padding:0; color:#637746;">
<div id="tlb_follow_total">
<?php
if ( $widget['show_followers'] == 'followers')
{
echo $twitter['followers_count'].' '.__('people follow',$wpb_prefix).' <strong>'. $widget['username'].'</strong>';
}
else
{
echo __('You follow ',$wpb_prefix). $twitter['friends_count'].__(' users',$wpb_prefix);
}
?>
</div>
<?php for($i=0; $i < $widget['total']; $i++) :?>
<span class="tlb_user_item">
<?php if($widget['link_followers'] == 'on' ): ?>
<a target="_blank" href="http://twitter.com/<?php echo $twitter['followers'][$i]['screen_name'];?>" title="<?php echo $twitter['followers'][$i]['screen_name'];?>" rel="nofollow">
<?php endif;?>
<img src="<?php echo $twitter['followers'][$i]['profile_image_url'];?>" width="48" height="48" alt="<?php echo $twitter['followers'][$i]['screen_name'];?>">
<span><?php echo substr($twitter['followers'][$i]['screen_name'], 0, 8);?></span>
<?php if($widget['link_followers'] == 'on' ): ?>
</a>
<?php endif;?>
</span>
<?php endfor;?>
<br style="clear:both">
</div>
<?php if ( $widget['options']['credits'] == 'true' ) echo '<div style="font-size:9px;text-align:right;">Widget By Timersys</div>';?>
<?php endif;//twitter error ?>
</div>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
</script>
<?php
}
$widget_code = ob_get_contents();
ob_end_clean();
return $widget_code;
}
/**
* Display widget
*/
static function display_widget($options){
echo Twitter_Like_Box_Widget::get_tlb_widget($options);
}
static function fetch_twitter_followers($options)
{
global $tlb,$you;
$cache_time = $tlb->_options['cache-time'];
$id = isset($options['id']) ? $options['id'] : 'widgets';
$key = 'tlb_'.$id.'_' . $options['username'];
// Let's see if we have a cached version
$followers = get_transient($key);
if ($followers !== false)
return $followers;
else
{
$tlb->connect();
$response = $tlb->connection->get("users/lookup", array('screen_name' => $options['username']));
if (Twitter_Like_Box_Widget::is_twitter_error($response))
{
// In case Twitter is down we return the last successful count
return get_option($key);
}
else
{
$json = $response;
#$you['name'] = $json[0]->name;
#$you['screen_name'] = $json[0]->screen_name;
#$you['followers_count'] = $json[0]->followers_count;
#$you['profile_image_url'] = $json[0]->profile_image_url;
#$you['friends_count'] = $json[0]->friends_count;
if ( $options['show_followers'] == 'followers' )
{
$fans = $tlb->connection->get('followers/ids',array('screen_name' => $options['username']));
}
else
{
$fans = $tlb->connection->get('friends/ids',array('screen_name' => $options['username']));
}
if (!Twitter_Like_Box_Widget::is_twitter_error($fans))
{
if ($options['total'] > 90 )
{
$fans_ids = array_chunk($fans->ids, 90);
$fans = array();
foreach ( $fans_ids as $ids_a )
{
$fans_ids = (string)implode( ',', $ids_a );
#$result = $tlb->connection->get('users/lookup',array('user_id' => $fans_ids ));
#$fans = array_merge($fans , $result );
}
}
else
{
$fans_ids = (string)implode( ',', array_slice($fans->ids, 0, $options['total']) );
#$fans = $tlb->connection->get('users/lookup',array('user_id' =>$fans_ids));
}
}
if( !Twitter_Like_Box_Widget::is_twitter_error($fans) && isset($fans[0]->screen_name) )
{
$followers = array();
for($i=0; $i < $options['total']; $i++)
{
$followers[$i]['screen_name'] = (string)$fans[$i]->screen_name;
$followers[$i]['profile_image_url'] = (string)$fans[$i]->profile_image_url;
}
$you['followers'] = $followers;
// Store the result in a transient, expires after 1 hour
// Also store it as the last successful using update_option
set_transient($key, $you, 60*60* $cache_time);
update_option($key, $you);
}
return $you;
}
}
}
static function is_twitter_error($response){
global $you,$tlb;
if(is_object($response) && isset($response->errors) )
{
$you['error'] = 'Error code: '. $response->errors[0]->code .'<br>Error message: '.$response->errors[0]->message;
$you['code'] = $response->errors[0]->code;
$tlb->log_error($you['error']);
return true;
}
if(is_object($response) && isset($response->ids) && empty($response->ids))
{
$you['error'] = '<br>Error message: You got no users to show. check if you have followers';
$tlb->log_error($you['error']);
return true;
}
return false;
}
} //end of class
Wordpress have ABSPATH variable defined in wp-config.php file, which contains the project's root path. Now we can include any file of wordpress codebase. eg.
require_once ABSPATH.'wp-includes/class-wp-widget.php';
I don't know the reason for the error, propably something with autoloading, but you can solve it if you include the file for the WP_Widget class in the first line.
require_once get_home_path()."wp-includes/class-wp-widget.php";
So,
I've been trying to make a template, which runs plugin functions.
Here is template I've tried to make.
And here are the errors I get
Warning: Invalid argument supplied for foreach() in C:\www\htdocs\FCN-GIT\wp-content\themes\Avada-Child-Theme\single-wpt_test.php on line 39
Fatal error: Call to undefined method WP::doAction() in C:\www\htdocs\FCN-GIT\wp-content\themes\Avada-Child-Theme\single-wpt_test.php on line 44
<?php
/**
* Template Name: Test
*
* #package WordPress
* #subpackage Avada
* #since 2016
*/
?>
<?php
// Can be overriden in your theme as entry-content-wpt-test-fill-form.php
/* #var $answerIdName string */
/* #var $answerIndex integer */
/* #var $isShowContent boolean */
/* #var $formAttributes array */
/* #var $content string */
/* #var $subTitle string */
/* #var $shortDescription string */
/* #var $test WpTesting_Model_Test */
/* #var $questions WpTesting_Model_Question[] */
/* #var $isFinal boolean */
/* #var $isMultipleAnswers boolean */
/* #var $submitButtonCaption string */
/* #var $stepsCounter string */
/* #var $wp WpTesting_WordPressFacade */
/* #var $hiddens array */
?>
<div class="wpt_test fill_form">
<?php if ($isShowContent): ?>
<div class="content">
<?php echo $content ?>
</div>
<?php endif ?>
<div class="content"><form
<?php foreach ($formAttributes as $key => $value):?>
<?php echo $key ?>="<?php echo htmlspecialchars(is_array($value) ? json_encode($value) : $value) ?>"
<?php endforeach ?>>
<?php if ($subTitle): ?><h2 class="subtitle"><?php echo $subTitle ?></h2><?php endif ?>
<?php if ($shortDescription): ?><div class="short-description"><?php echo $wp->autoParagraphise($shortDescription) ?></div><?php endif ?>
<?php $wp->doAction('wp_testing_template_fill_form_questions_before') ?>
<?php foreach($questions as $q => $question): /* #var $question WpTesting_Model_Question */ ?>
<?php $wp->doAction('wp_testing_template_fill_form_question_before', $question, $q) ?>
<div class="question">
<div class="title">
<span class="number"><?php echo $q+1 ?>.</span><span class="title"><?php echo $question->getTitle() ?>
<?php $wp->doAction('wp_testing_template_fill_form_label_end', array('required' => true)) ?></span>
<?php if (!$isMultipleAnswers): ?>
<input type="hidden" name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="" />
<?php endif ?>
</div>
<?php foreach($question->buildAnswers() as $a => $answer): /* #var $answer WpTesting_Model_Answer */ ?>
<?php $answerId = 'wpt-test-question-' . $question->getId() . '-answer-' . $answer->getId() ?>
<div class="answer">
<label for="<?php echo $answerId ?>">
<input type="<?php echo $isMultipleAnswers ? 'checkbox' : 'radio' ?>" id="<?php echo $answerId ?>"
data-errormessage="<?php echo $isMultipleAnswers
? __('Please select at least one answer.', 'wp-testing')
: __('Please choose only one answer.', 'wp-testing') ?>"
<?php if (0 == $a): ?>required="required" aria-required="true"<?php endif ?>
name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="<?php echo $answer->getId() ?>" />
<?php echo $answer->getTitleOnce() ?>
</label>
</div>
<?php if ($isMultipleAnswers) {$answerIndex++;} ?>
<?php endforeach ?>
</div>
<?php $wp->doAction('wp_testing_template_fill_form_question_after', $question, $q) ?>
<?php if (!$isMultipleAnswers) {$answerIndex++;} ?>
<?php endforeach ?>
<?php $wp->doAction('wp_testing_template_fill_form_questions_after') ?>
<?php if($isFinal): ?>
<p>
<input type="submit" class="button" value="<?php echo $submitButtonCaption ?>" />
<?php if($stepsCounter): ?><span class="steps-counter"><?php echo $stepsCounter ?></span><?php endif ?>
</p>
<?php else: ?>
<div class="wpt_warning">
<h4><?php echo __('Test is under construction', 'wp-testing') ?></h4>
<p><?php echo __('You can not get any results from it yet.', 'wp-testing') ?></p>
</div>
<?php endif ?>
<?php foreach($hiddens as $name => $value): ?><input type="hidden" name="<?php echo htmlspecialchars($name) ?>" value="<?php echo htmlspecialchars($value) ?>" /><?php endforeach ?>
</form></div>
</div>
I managed to fix this, but overriding the default template of the plugin, I needed to have two templates which differences in one, so essentially, a template which has code for my homepage and for another page.
The homepage has the changes, and the other page does not, and it uses the default theme template.
Here was my solution to having two templates in one using the plugin code.
<?php
// Can be overriden in your theme as entry-content-wpt-test-fill-form.php
/* #var $answerIdName string */
/* #var $answerIndex integer */
/* #var $isShowContent boolean */
/* #var $formAttributes array */
/* #var $content string */
/* #var $subTitle string */
/* #var $shortDescription string */
/* #var $test WpTesting_Model_Test */
/* #var $questions WpTesting_Model_Question[] */
/* #var $isFinal boolean */
/* #var $isMultipleAnswers boolean */
/* #var $submitButtonCaption string */
/* #var $stepsCounter string */
/* #var $wp WpTesting_WordPressFacade */
/* #var $hiddens array */
?>
<?php if (is_front_page()): ?>
<div class="home-health-insight wpt_test fill_form">
<div class="answers">
<div class="content">
<form
<?php foreach ($formAttributes as $key => $value):?>
<?php echo $key ?>="<?php echo htmlspecialchars(is_array($value) ? json_encode($value) : $value) ?>"
<?php endforeach; ?>>
<?php if ($isShowContent): ?><div class="content" style="margin:0;"><?php echo $content ?></div><?php endif ?>
<?php if ($shortDescription): ?><div class="short-description"><?php echo $wp->autoParagraphise($shortDescription) ?></div><?php endif ?>
<?php $wp->doAction('wp_testing_template_fill_form_questions_before') ?>
<div class="question">
<div class="question-titles">
<div class="question-labels">
<label class="answerlbl" for="<?php echo $answerId ?>">
None of the time
</label>
<label class="answerlbl" for="<?php echo $answerId ?>">
Rarely
</label>
<label class="answerlbl" for="<?php echo $answerId ?>">
Some of the time
</label>
<label class="answerlbl" for="<?php echo $answerId ?>">
Often
</label>
<label class="answerlbl" for="<?php echo $answerId ?>">
All of the time
</label>
</div>
</div>
<?php foreach($questions as $q => $question): /* #var $question WpTesting_Model_Question */ ?>
<?php $wp->doAction('wp_testing_template_fill_form_question_before', $question, $q) ?>
<div class="title">
<span class="question-title" style="width:100%;"><?php echo $question->getTitle() ?>
<?php $wp->doAction('wp_testing_template_fill_form_label_end', array('required' => true)) ?></span>
<?php if (!$isMultipleAnswers): ?>
<input type="hidden" name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="" />
<?php endif ?>
</div>
<div class="answer-block">
<?php foreach($question->buildAnswers() as $a => $answer): /* #var $answer WpTesting_Model_Answer */ ?>
<?php $answerId = 'wpt-test-question-' . $question->getId() . '-answer-' . $answer->getId() ?>
<div class="answer">
<input type="<?php echo $isMultipleAnswers ? 'checkbox' : 'radio' ?>" id="<?php echo $answerId ?>"
data-errormessage="<?php echo $isMultipleAnswers
? __('Please select at least one answer.', 'wp-testing')
: __('Please choose only one answer.', 'wp-testing') ?>"
<?php if (0 == $a): ?>required="required" aria-required="true"<?php endif ?>
name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="<?php echo $answer->getId() ?>" />
</div>
<?php if ($isMultipleAnswers) {$answerIndex++;} ?>
<?php endforeach ?>
</div>
<?php $wp->doAction('wp_testing_template_fill_form_question_after', $question, $q) ?>
<?php if (!$isMultipleAnswers) {$answerIndex++;} ?>
<?php endforeach ?>
</div>
<?php $wp->doAction('wp_testing_template_fill_form_questions_after') ?>
<?php if($isFinal): ?>
<p>
<input type="submit" class="button" value="<?php echo $submitButtonCaption ?>" />
<?php if($stepsCounter): ?><span class="steps-counter"><?php echo $stepsCounter ?></span><?php endif ?>
</p>
<?php else: ?>
<div class="wpt_warning">
<h4><?php echo __('Test is under construction', 'wp-testing') ?></h4>
<p><?php echo __('You can not get any results from it yet.', 'wp-testing') ?></p>
</div>
<?php endif ?>
<?php foreach($hiddens as $name => $value): ?><input type="hidden" name="<?php echo htmlspecialchars($name) ?>" value="<?php echo htmlspecialchars($value) ?>" /><?php endforeach ?>
</form>
</div>
</div>
</div>
<?php else: ?>
<div class="wpt_test fill_form">
<?php if ($isShowContent): ?>
<div class="content">
<?php echo $content ?>
</div>
<?php endif ?>
<div class="content"><form
<?php foreach ($formAttributes as $key => $value):?>
<?php echo $key ?>="<?php echo htmlspecialchars(is_array($value) ? json_encode($value) : $value) ?>"
<?php endforeach ?>>
<?php if ($subTitle): ?><h2 class="subtitle"><?php echo $subTitle ?></h2><?php endif ?>
<?php if ($shortDescription): ?><div class="short-description"><?php echo $wp->autoParagraphise($shortDescription) ?></div><?php endif ?>
<?php $wp->doAction('wp_testing_template_fill_form_questions_before') ?>
<?php foreach($questions as $q => $question): /* #var $question WpTesting_Model_Question */ ?>
<?php $wp->doAction('wp_testing_template_fill_form_question_before', $question, $q) ?>
<div class="question">
<div class="title">
<span class="number"><?php echo $q+1 ?>.</span><span class="title"><?php echo $question->getTitle() ?>
<?php $wp->doAction('wp_testing_template_fill_form_label_end', array('required' => true)) ?></span>
<?php if (!$isMultipleAnswers): ?>
<input type="hidden" name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="" />
<?php endif ?>
</div>
<?php foreach($question->buildAnswers() as $a => $answer): /* #var $answer WpTesting_Model_Answer */ ?>
<?php $answerId = 'wpt-test-question-' . $question->getId() . '-answer-' . $answer->getId() ?>
<div class="answer">
<label for="<?php echo $answerId ?>">
<input type="<?php echo $isMultipleAnswers ? 'checkbox' : 'radio' ?>" id="<?php echo $answerId ?>"
data-errormessage="<?php echo $isMultipleAnswers
? __('Please select at least one answer.', 'wp-testing')
: __('Please choose only one answer.', 'wp-testing') ?>"
<?php if (0 == $a): ?>required="required" aria-required="true"<?php endif ?>
name="<?php echo $answerIdName ?>[<?php echo $answerIndex ?>]" value="<?php echo $answer->getId() ?>" />
<?php echo $answer->getTitleOnce() ?>
</label>
</div>
<?php if ($isMultipleAnswers) {$answerIndex++;} ?>
<?php endforeach ?>
</div>
<?php $wp->doAction('wp_testing_template_fill_form_question_after', $question, $q) ?>
<?php if (!$isMultipleAnswers) {$answerIndex++;} ?>
<?php endforeach ?>
<?php $wp->doAction('wp_testing_template_fill_form_questions_after') ?>
<?php if($isFinal): ?>
<p>
<input type="submit" class="button" value="<?php echo $submitButtonCaption ?>" />
<?php if($stepsCounter): ?><span class="steps-counter"><?php echo $stepsCounter ?></span><?php endif ?>
</p>
<?php else: ?>
<div class="wpt_warning">
<h4><?php echo __('Test is under construction', 'wp-testing') ?></h4>
<p><?php echo __('You can not get any results from it yet.', 'wp-testing') ?></p>
</div>
<?php endif ?>
<?php foreach($hiddens as $name => $value): ?><input type="hidden" name="<?php echo htmlspecialchars($name) ?>" value="<?php echo htmlspecialchars($value) ?>" /><?php endforeach ?>
</form></div>
</div>
<?php endif ?>
I have a script that is reading my wheel brands. If I select a wheel it show all the wheels from that brand...
But because I did GROUP BY merk_naam so in my dropdown there wont be 100 same brands I cant show them all...
Can somebody help me with the following:
I have two tables now:
Table 1: it_merken
Table 1
Table 2: it_merken2
Table 2
I want the merk_naam in a dropdown list
But when I do that I get a lot of double ones like AS 2 time in this example...
I want to JOIN in table 1 and table 2 the merk_naam in one query...
I cant figure out how...
Can somebody help me out?
This is the class I got now with the GROUP BY:
<?php
class merken extends connect
{
/**
* Merken lijst
*
* #param object
*/
private $merkenlijst;
/**
* Vraag merken op uit database
*
* #param int $id
* #return array
*/
public function getMerken($database, $id = NULL)
{
$sql = "SELECT merk_code, merk_logo, merk_naam, wiel_foto, wiel_nummer, wiel_info FROM ".$database."_merken";
if(!empty($id))
{
$sql .= " WHERE merk_code=:id";
}
else
{
$sql .= " GROUP BY merk_naam";
}
try
{
$stmt = $this->db->prepare($sql);
if(!empty($id)){ $stmt->bindParam(":id", $id, PDO::PARAM_STR); }
$stmt->execute();
$this->merkenlijst = $stmt->fetchAll(PDO::FETCH_OBJ);
$stmt->closeCursor();
return $this->merkenlijst;
}
catch (Exception $e)
{
die ( $e->getMessage() );
}
}
/**
* Maak een database object en sla de data op
*
* #param object $dbo
* #return void
*/
public function __construct($dbo = NULL)
{
/*
* Roep de parent constructor aan om te controleren op
* een database object
*/
parent::__construct($dbo);
}
}
?>
That is given me each brand one time in my dropdown but when I select nothing, I want to show all brands and because I use GROUP BY now I only see one wheel per brand after submit.
This is my PHP and HTML:
<div class="bandwielkolom">
<form name="wielenzoeken" action="index.php?lang=<?php echo $lang; ?>&p=<?php echo $_GET['p']; ?>#keuze" method="post">
<table class="wielentabel">
<tr>
<th colspan="2"><?php echo $searchwheelsbybrand; ?><a name="wiel"></a></th>
</tr>
<tr>
<td><?php echo $brand; ?>:</td>
<td>
<select name="wiel_merk" onchange="enable()">
<option value="0">- <?php echo $brand; ?> -</option>
<?php
$merken = $merkclass->getMerken($website, $merk);
foreach($merken as $merk)
{
echo "\t\t\t\t\t\t\t\t\t\t\t<option value=\"".$merk->merk_code."\"";
if(isset($_GET['search']) && $_GET['search'] == "wiel" && isset($_GET['merk']) && $_GET['merk'] != "0" || isset($_POST['wiel_submit']) && $_POST['wiel_merk'] != "0") { echo " selected=\"selected\""; }
echo ">".$merk->merk_naam."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="wiel_submit" value="<?php echo $search; ?>"/></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</form>
</div>
</div>
<div class="clearboth"></div>
<div id="main-right">
<?php
foreach($teksten as $tekst)
{
?>
<h1><strong><?php echo $tekst->tekst_header; ?></strong></h1>
<?php echo $tekst->tekst_content."\n"; ?>
<?php
if(!empty($tekst->tekst_img))
{
?>
<div class="imgcontainer">
<div class="imgcontent">
<img src="<?php echo $tekst->tekst_img; ?>" class="content_image" alt="<?php echo $tekst->tekst_header; ?>" />
</div>
</div>
<?php
}
?>
<?php
}
?>
</div>
</div>
<div class="clearboth"></div>
<div id="main-left">
<ul class="wheels">
<?php
if(isset($_POST['wiel_submit']) && $_POST['wiel_submit'] == $search || isset($_GET['merk']))
{
$merk = NULL;
if(isset($_POST['wiel_submit']) && $_POST['wiel_submit'] == $search)
{
echo "\t\t\t\t\t<h2>".$brandselection."</h2>
\t\t\t\t\t<br />\n";
$merk = $_POST['wiel_merk'];
}
?>
<?php
$merken = $merkclass->getMerken($website, $merk);
foreach($merken as $merk)
{
?>
<li><span class="title"><?php echo $merk->wiel_info; ?></span>
<a href="http://www.website.nl/website/images/w3/<?php echo $merk->wiel_foto; ?>" class="preview" title="Fotonummer: <?php echo $merk->wiel_foto; ?>">
<img src="http://www.website.nl/website/images/w3/<?php echo $merk->wiel_foto; ?>" alt="Fotonummer: <?php echo $merk->wiel_foto; ?>" class="wheelImg"/>
</a>
<span class="descr">
<img src="http://www.website.net/preview/bnet/logos/<?php echo str_replace(".png", "_100.png", $merk->merk_logo); ?>" style="padding-left:45px;" width="100" class="logo-merk" alt="<?php echo $merk->merk_naam; ?>"/>
</span>
</li>
<?php
}
?>
</ul>
<?php
}
?>
</div>
Any help is welcome because I can't figure it out!
You are getting doubles because some some of the fields in your SQL do not match, so you get a record for each.