dcuellar Posted January 28, 2008 Share Posted January 28, 2008 Forgive me if this is elementary. I am just learning php. I'm trying to set a limit to how many popular products appear on the page in my online store. http://www.unifiedchamp.com/ucforum/cartplog.php I'd like to set the limit to no more than 10 items. This is what I have to work with. $cartplog['popular_products'] = ''; while ($cartplog_product_info = $db->fetch_array($cartplog_product_infos)) { $cartplog['product_productid'] = intval($cartplog_product_info['productid']); $cartplog['product_catid'] = intval($cartplog_product_info['catid']); $cartplog['product_thumb'] = strval($cartplog_product_info['thumb']); $cartplog['product_title'] = htmlspecialchars_uni($cartplog_product_info['title']); $cartplog['product_price'] = round(floatval($cartplog_product_info['price']), 2); eval('$cartplog[\'popular_products\'] .= "' . fetch_template('cartplog_product_item') . '";'); $cartplog['popular_products'] .= '</tr><tr>'; } $db->free_result($cartplog_product_infos); $cartplog['popular_products'] = eregi_replace(preg_quote('</tr><tr>') . '$', '', $cartplog['popular_products']); Any help with this would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/ Share on other sites More sharing options...
only one Posted January 28, 2008 Share Posted January 28, 2008 while ($cartplog_product_info = $db->fetch_array($cartplog_product_infos) && $i <= 10) { $i++; $cartplog['product_productid'] = intval($cartplog_product_info['productid']); $cartplog['product_catid'] = intval($cartplog_product_info['catid']); $cartplog['product_thumb'] = strval($cartplog_product_info['thumb']); $cartplog['product_title'] = htmlspecialchars_uni($cartplog_product_info['title']); $cartplog['product_price'] = round(floatval($cartplog_product_info['price']), 2); eval('$cartplog[\'popular_products\'] .= "' . fetch_template('cartplog_product_item') . '";'); $cartplog['popular_products'] .= '</tr><tr>'; } Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451524 Share on other sites More sharing options...
effigy Posted January 28, 2008 Share Posted January 28, 2008 If you're using MySQL, you can add LIMIT 10 to the SQL. Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451527 Share on other sites More sharing options...
dcuellar Posted January 28, 2008 Author Share Posted January 28, 2008 you guys are unbelievably fast!! While I appreciate your responses, I must add, I am a beginner. I was told by the developer that I should just add a limit to the php. Onlyone, am I replacing mine with what you wrote? effigy, I'm sorry, I don't know what I'm using. Can you explain? Thank you so much guys. I've been surfing the web for a while and you will definitely be my hope for php questions! Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451530 Share on other sites More sharing options...
dcuellar Posted January 28, 2008 Author Share Posted January 28, 2008 only one, I got what you were saying... I'll try it and tell you what happened. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451536 Share on other sites More sharing options...
dcuellar Posted January 28, 2008 Author Share Posted January 28, 2008 only one, I tried that and it caused the images on the right hand side to be deleted. Any ideas why? It also caused the newest product picture to be deleted. http://www.unifiedchamp.com/ucforum/cartplog.php Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451544 Share on other sites More sharing options...
duclet Posted January 28, 2008 Share Posted January 28, 2008 You are wasting memory by adding the counter in the while loop. effigy's solution is the better one. Just add LIMIT 10 right before the semicolon of your SQL statement or if it doesn't have a semicolon, add it at the end. Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451549 Share on other sites More sharing options...
dcuellar Posted January 28, 2008 Author Share Posted January 28, 2008 You are wasting memory by adding the counter in the while loop. effigy's solution is the better one. Just add LIMIT 10 right before the semicolon of your SQL statement or if it doesn't have a semicolon, add it at the end. what is my SQL statement? Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451554 Share on other sites More sharing options...
aebstract Posted January 28, 2008 Share Posted January 28, 2008 It's not in the code you posted, so we couldn't tell you exactly. It is somewhere before it and it's the code where you connect to your database to retrieve your information. Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451559 Share on other sites More sharing options...
dcuellar Posted January 28, 2008 Author Share Posted January 28, 2008 <?php /********************************************************************************************* CartPlog Lite License ============================================================================================== This software is as-is, no warranty of any kind, use at your own risk. You are granted free use of this software. However, you are not permitted under any circumstances to redistribute the software, whether in whole or in part. Also, the 'powered by' links must remain intact and visible. Make sure to understand that this is *not GPL software. Do not redistribute it, and do not use parts of it in other software. This software is copyrighted in its entirety to 'calorie' a/k/a © ThinkDing LLC 2007, all rights reserved. The software author/entity are in no way responsible for your site content. All copyright notices and 'powered by' links must not be changed or removed. Do not use this software if obtained from a warez site! *********************************************************************************************/ // ####################### SET PHP ENVIRONMENT ############################ error_reporting(E_ALL & ~E_NOTICE); // #################### DEFINE IMPORTANT CONSTANTS ######################## define('THIS_SCRIPT', 'cartplog'); define('CARTPLOG_VERSION', 'Lite v.1.0.0'); if ($_REQUEST['do'] == 'postback') { define('SKIP_SESSIONCREATE', 1); } // ################### PRE-CACHE TEMPLATES AND DATA ####################### if (empty($_REQUEST['do'])) { $_REQUEST['do'] = 'viewindex'; } $phrasegroups = array('cartplogfrontend'); $specialtemplates = array(); $globaltemplates = array(); $actiontemplates = array( 'checkout' => array( 'cartplog_basket_item', 'cartplog_view_cart' ), 'viewcart' => array( 'cartplog_basket_item', 'cartplog_view_cart' ), 'viewcategory' => array( 'cartplog_category_item', 'cartplog_view_category' ), 'viewhistory' => array( 'cartplog_history_item', 'cartplog_history_list', 'cartplog_view_history' ), 'viewindex' => array( 'cartplog_category_list', 'cartplog_basket_summary', 'cartplog_product_item', 'cartplog_view_index' ), 'viewitem' => array( 'cartplog_view_item' ) ); // ####################### REQUIRE VB BACK-END ############################ // cartplog in main forum directory require_once('./global.php'); // ###################### CHECK CARTPLOG ACCESS ########################### if ($_REQUEST['do'] != 'postback') { if (!$vbulletin->options['cartplog_active'] || !$vbulletin->userinfo['userid']) { print_no_permission(); } } // #################### INITIALIZE SOME VARIABLES ######################### $cartplog = array(); // do not remove this !!! // do not hide, change, remove, etcetera !!! $cartplog['powered_by'] = '<br /><div class="smallfont" align="center"><a href="http://www.photoplog.com/">' . $vbphrase['cartplog_powered_by_cartplog'] . ' ' . CARTPLOG_VERSION . '</a></div>'; // do not hide, change, remove, etcetera !!! $footer = $cartplog['powered_by'] . $footer; $cartplog_currencies = array('AUD', 'CAD', 'EUR', 'GBP', 'USD'); $cartplog['currency_code'] = 'USD'; if (isset($cartplog_currencies[$vbulletin->options['cartplog_currency']])) { $cartplog['currency_code'] = $cartplog_currencies[$vbulletin->options['cartplog_currency']]; } // #################### INITIALIZE COOKIE SESSION ######################### if ($_REQUEST['do'] != 'postback') { $vbulletin->input->clean_array_gpc('c', array( COOKIE_PREFIX . 'cartplog' => TYPE_NOHTML )); $cartplog['cookie'] = $vbulletin->GPC[COOKIE_PREFIX . 'cartplog']; if ($cartplog['cookie']) { $cartplog_count_check = $db->query_first("SELECT COUNT(*) AS cnt FROM " . TABLE_PREFIX . "cartplog_sessions WHERE userid = " . intval($vbulletin->userinfo['userid']) . " AND sessionid = '" . $db->escape_string($cartplog['cookie']) . "' AND completed = 0 "); if ($cartplog_count_check['cnt'] != 1) { $cartplog['cookie'] = ''; vbsetcookie('cartplog', '', false); } } if (empty($cartplog['cookie'])) { $cartplog_hash = rand() . TIMENOW . uniqid(microtime(), true) . $vbulletin->userinfo['userid']; $cartplog['cookie'] = md5($cartplog_hash); $cartplog_flag = true; while ($cartplog_flag) { $cartplog_count_check = $db->query_first("SELECT COUNT(*) AS cnt FROM " . TABLE_PREFIX . "cartplog_sessions WHERE userid = " . intval($vbulletin->userinfo['userid']) . " AND sessionid = '" . $db->escape_string($cartplog['cookie']) . "' "); if ($cartplog_count_check['cnt']) { $cartplog_hash = rand() . TIMENOW . uniqid(microtime(), true) . $vbulletin->userinfo['userid']; $cartplog['cookie'] = md5($cartplog_hash); } else { $cartplog_flag = false; $db->query_write("INSERT INTO " . TABLE_PREFIX . "cartplog_sessions (sessionid, userid, completed, dateline, products) VALUES ( '" . $db->escape_string($cartplog['cookie']) . "', " . intval($vbulletin->userinfo['userid']) . ", 0, " . intval(TIMENOW) . ", 'a:0:{}' ) "); vbsetcookie('cartplog', $cartplog['cookie']); } } } } else if ($_REQUEST['do'] == 'postback') { $vbulletin->nozip = true; } // ######################## START MAIN SCRIPT ############################# if ($_REQUEST['do'] == 'viewindex') { // full table scan but no one should have millions of products $cartplog_product_infos = $db->query_read("SELECT productid, catid, thumb, title, price, sales FROM " . TABLE_PREFIX . "cartplog_products ORDER BY RAND() "); $cartplog['product_list'] = ''; $cartplog_count = 0; $cartplog_max_productid = 0; $cartplog_max_salescnt = 0; while ($cartplog_product_info = $db->fetch_array($cartplog_product_infos)) { $cartplog_count ++; $cartplog['product_productid'] = intval($cartplog_product_info['productid']); $cartplog['product_catid'] = intval($cartplog_product_info['catid']); $cartplog['product_thumb'] = strval($cartplog_product_info['thumb']); $cartplog['product_title'] = htmlspecialchars_uni($cartplog_product_info['title']); $cartplog['product_price'] = round(floatval($cartplog_product_info['price']), 2); $cartplog['product_sales'] = intval($cartplog_product_info['sales']); $cartplog_max_productid = max($cartplog_max_productid, $cartplog['product_productid']); $cartplog_max_salescnt = max($cartplog_max_salescnt, $cartplog['product_sales']); eval('$cartplog[\'product_list\'] .= "' . fetch_template('cartplog_product_item') . '";'); if ($cartplog_count % 3 == 0) { $cartplog['product_list'] .= '</tr><tr>'; } } $db->free_result($cartplog_product_infos); $cartplog['product_list'] = eregi_replace(preg_quote('</tr><tr>') . '$', '', $cartplog['product_list']); while ($cartplog_count % 3 != 0) { $cartplog['product_list'] .= '<td class="alt1" align="center" valign="bottom"> </td>'; $cartplog_count ++; } $cartplog_count = 0; $cartplog_product_info = $db->query_first("SELECT productid, catid, thumb, title, price FROM " . TABLE_PREFIX . "cartplog_products WHERE productid = " . intval($cartplog_max_productid) . " "); $cartplog['newest_product'] = ''; $cartplog['product_productid'] = intval($cartplog_product_info['productid']); $cartplog['product_catid'] = intval($cartplog_product_info['catid']); $cartplog['product_thumb'] = strval($cartplog_product_info['thumb']); $cartplog['product_title'] = htmlspecialchars_uni($cartplog_product_info['title']); $cartplog['product_price'] = round(floatval($cartplog_product_info['price']), 2); eval('$cartplog[\'newest_product\'] .= "' . fetch_template('cartplog_product_item') . '";'); $db->free_result($cartplog_product_info); $cartplog_product_infos = $db->query_read("SELECT productid, catid, thumb, title, price FROM " . TABLE_PREFIX . "cartplog_products WHERE sales = " . intval($cartplog_max_salescnt) . " "); $cartplog['popular_products'] = ''; while ($cartplog_product_info = $db->fetch_array($cartplog_product_infos)) { $cartplog['product_productid'] = intval($cartplog_product_info['productid']); $cartplog['product_catid'] = intval($cartplog_product_info['catid']); $cartplog['product_thumb'] = strval($cartplog_product_info['thumb']); $cartplog['product_title'] = htmlspecialchars_uni($cartplog_product_info['title']); $cartplog['product_price'] = round(floatval($cartplog_product_info['price']), 2); eval('$cartplog[\'popular_products\'] .= "' . fetch_template('cartplog_product_item') . '";'); $cartplog['popular_products'] .= '</tr><tr>'; } $db->free_result($cartplog_product_infos); $cartplog['popular_products'] = eregi_replace(preg_quote('</tr><tr>') . '$', '', $cartplog['popular_products']); $cartplog_category_infos = $db->query_read("SELECT catid, title, products FROM " . TABLE_PREFIX . "cartplog_categories ORDER BY displayorder "); $cartplog['category_list'] = ''; while ($cartplog_category_info = $db->fetch_array($cartplog_category_infos)) { $cartplog['category_catid'] = intval($cartplog_category_info['catid']); $cartplog['category_products'] = intval($cartplog_category_info['products']); $cartplog['category_title'] = htmlspecialchars_uni($cartplog_category_info['title']); eval('$cartplog[\'category_list\'] .= "' . fetch_template('cartplog_category_list') . '";'); } $db->free_result($cartplog_category_infos); $cartplog_basket_check = $db->query_first("SELECT products FROM " . TABLE_PREFIX . "cartplog_sessions WHERE userid = " . intval($vbulletin->userinfo['userid']) . " AND sessionid = '" . $db->escape_string($cartplog['cookie']) . "' "); $cartplog['basket_count'] = 0; $cartplog['basket_total'] = 0; if ($cartplog_basket_check['products']) { $cartplog_basket_check['products'] = unserialize($cartplog_basket_check['products']); if (!is_array($cartplog_basket_check['products'])) { $cartplog_basket_check['products'] = array(); } foreach($cartplog_basket_check['products'] AS $cartplog_basket_productid => $cartplog_basket_array) { $cartplog['basket_count'] += intval($cartplog_basket_array['quantity']); $cartplog['basket_total'] += round(intval($cartplog_basket_array['quantity']) * floatval($cartplog_basket_array['price']), 2); } } else { $cartplog_basket_check['products'] = array(); } $db->free_result($cartplog_basket_check); $cartplog['basket_total'] = number_format($cartplog['basket_total'], 2, '.', ''); eval('$cartplog[\'basket_summary\'] = "' . fetch_template('cartplog_basket_summary') . '";'); $navbits = array(); $navbits['cartplog.php' . $vbulletin->session->vars['sessionurl_q']] = htmlspecialchars_uni($vbphrase['cartplog']); $navbits[''] = htmlspecialchars_uni($vbphrase['cartplog_shopping_cart']); $navbits = construct_navbits($navbits); eval('$navbar = "' . fetch_template('navbar') . '";'); eval('print_output("' . fetch_template('cartplog_view_index') . '");'); } if ($_REQUEST['do'] == 'viewcategory') { $vbulletin->input->clean_array_gpc('r', array( 'cartplogcatid' => TYPE_UINT, )); $cartplog['categoryid'] = $vbulletin->GPC['cartplogcatid']; $cartplog_product_infos = $db->query_read("SELECT productid, thumb, title, price FROM " . TABLE_PREFIX . "cartplog_products WHERE catid = " . intval($cartplog['categoryid']) . " "); $cartplog['category_items'] = ''; if ($cartplog_product_infos) { while ($cartplog_product_info = $db->fetch_array($cartplog_product_infos)) { $cartplog['productid'] = intval($cartplog_product_info['productid']); $cartplog['thumb'] = strval($cartplog_product_info['thumb']); $cartplog['title'] = htmlspecialchars_uni($cartplog_product_info['title']); $cartplog['price'] = round(floatval($cartplog_product_info['price']), 2); eval('$cartplog[\'category_items\'] .= "' . fetch_template('cartplog_category_item') . '";'); } $db->free_result($cartplog_product_infos); $navbits = array(); $navbits['cartplog.php' . $vbulletin->session->vars['sessionurl_q']] = htmlspecialchars_uni($vbphrase['cartplog']); $navbits[''] = htmlspecialchars_uni($vbphrase['cartplog_view_category']); $navbits = construct_navbits($navbits); eval('$navbar = "' . fetch_template('navbar') . '";'); eval('print_output("' . fetch_template('cartplog_view_category') . '");'); } else { $cartplog_url = 'cartplog.php?' . $vbulletin->session->vars['sessionurl'] . 'do=viewindex'; exec_header_redirect($cartplog_url); exit(); } } if ($_REQUEST['do'] == 'viewcart' || $_REQUEST['do'] == 'checkout') { $cartplog['checkout'] = 0; if ($_REQUEST['do'] == 'checkout') { $cartplog['checkout'] = 1; $cartplog_paypal_api = $db->query_first("SELECT settings FROM " . TABLE_PREFIX . "paymentapi WHERE classname = 'paypal' "); $cartplog['ppemail'] = ''; $cartplog['primaryemail'] = ''; $cartplog_paypal_api['settings'] = unserialize($cartplog_paypal_api['settings']); if (is_array($cartplog_paypal_api['settings'])) { foreach($cartplog_paypal_api['settings'] AS $cartplog_paypal_api_title => $cartplog_paypal_api_array) { if ($cartplog_paypal_api_title == 'ppemail') { $cartplog['ppemail'] = strtolower($cartplog_paypal_api_array['value']); } if ($cartplog_paypal_api_title == 'primaryemail') { $cartplog['primaryemail'] = strtolower($cartplog_paypal_api_array['value']); } } } } $cartplog_basket_check = $db->query_first("SELECT products FROM " . TABLE_PREFIX . "cartplog_sessions WHERE userid = " . intval($vbulletin->userinfo['userid']) . " AND sessionid = '" . $db->escape_string($cartplog['cookie']) . "' "); $cartplog['basket_items'] = ''; $cartplog['basket_total'] = 0; $cartplog['basket_hidden'] = ''; $cartplog['xnum'] = 0; if ($cartplog_basket_check['products']) { $cartplog_basket_check['products'] = unserialize($cartplog_basket_check['products']); if (!is_array($cartplog_basket_check['products'])) { $cartplog_basket_check['products'] = array(); } foreach($cartplog_basket_check['products'] AS $cartplog_basket_productid => $cartplog_basket_array) { $cartplog['basket_productid'] = intval($cartplog_basket_productid); $cartplog['basket_quantity'] = intval($cartplog_basket_array['quantity']); $cartplog['basket_thumb'] = strval($cartplog_basket_array['thumb']); $cartplog['basket_title'] = htmlspecialchars_uni($cartplog_basket_array['title']); $cartplog['basket_price'] = round(floatval($cartplog_basket_array['price']), 2); $cartplog['basket_options'] = nl2br(htmlspecialchars_uni($cartplog_basket_array['options'])); $cartplog['basket_lineprice'] = round($cartplog['basket_quantity'] * $cartplog['basket_price'], 2); $cartplog['basket_total'] += $cartplog['basket_lineprice']; eval('$cartplog[\'basket_items\'] .= "' . fetch_template('cartplog_basket_item') . '";'); if ($cartplog['checkout']) { $cartplog['xnum'] ++; $cartplog['basket_options'] = str_replace('<br />', ', ', $cartplog['basket_options']); if (!vbstrlen($cartplog['basket_options'])) { $cartplog['basket_options'] = $vbphrase['none']; } $cartplog['basket_hidden'] .= ' <input type="hidden" name="item_name_' . $cartplog['xnum'] . '" value="' . $cartplog['basket_title'] . '" /> <input type="hidden" name="item_number_' . $cartplog['xnum'] . '" value="' . $cartplog['cookie'] . '" /> <input type="hidden" name="amount_' . $cartplog['xnum'] . '" value="' . $cartplog['basket_price'] . '" /> <input type="hidden" name="quantity_' . $cartplog['xnum'] . '" value="' . $cartplog['basket_quantity'] . '" /> <input type="hidden" name="shipping_' . $cartplog['xnum'] . '" value="0.00" /> <input type="hidden" name="on0_' . $cartplog['xnum'] . '" value="' . $vbphrase['options'] . '" /> <input type="hidden" name="os0_' . $cartplog['xnum'] . '" value="' . $cartplog['basket_options'] . '" /> '; } } } else { $cartplog_basket_check['products'] = array(); } $cartplog['basket_total'] = number_format($cartplog['basket_total'], 2, '.', ''); $navbits = array(); $navbits['cartplog.php' . $vbulletin->session->vars['sessionurl_q']] = htmlspecialchars_uni($vbphrase['cartplog']); $navbits[''] = htmlspecialchars_uni($vbphrase['cartplog_view_cart']); $navbits = construct_navbits($navbits); eval('$navbar = "' . fetch_template('navbar') . '";'); eval('print_output("' . fetch_template('cartplog_view_cart') . '");'); } if ($_REQUEST['do'] == 'viewhistory') { $cartplog_transaction_infos = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "cartplog_transactions WHERE userid = " . intval($vbulletin->userinfo['userid']) . " ORDER BY dateline DESC "); $cartplog['history_items'] = ''; $cartplog['history_list'] = ''; while ($cartplog_transaction_info = $db->fetch_array($cartplog_transaction_infos)) { $cartplog['history_items'] = ''; $cartplog['sessionid'] = htmlspecialchars_uni($cartplog_transaction_info['sessionid']); $cartplog['total'] = round(floatval($cartplog_transaction_info['total']), 2); $cartplog['status'] = htmlspecialchars_uni($cartplog_transaction_info['status']); $cartplog['date'] = vbdate($vbulletin->options['dateformat'], intval($cartplog_transaction_info['dateline'])); $cartplog_transaction_info['products'] = unserialize($cartplog_transaction_info['products']); if (!is_array($cartplog_transaction_info['products'])) { $cartplog_transaction_info['products'] = array(); } foreach($cartplog_transaction_info['products'] AS $cartplog_transaction_productid => $cartplog_transaction_array) { $cartplog['productid'] = intval($cartplog_transaction_productid); $cartplog['quantity'] = intval($cartplog_transaction_array['quantity']); $cartplog['thumb'] = strval($cartplog_transaction_array['thumb']); $cartplog['title'] = htmlspecialchars_uni($cartplog_transaction_array['title']); $cartplog['price'] = round(floatval($cartplog_transaction_array['price']), 2); $cartplog['options'] = nl2br(htmlspecialchars_uni($cartplog_transaction_array['options'])); $cartplog['lineprice'] = round($cartplog['quantity'] * $cartplog['price'], 2); if ($cartplog['thumb']) { $cartplog['thumb'] = '<img style="' . $vbulletin->options['cartplog_thumbcss'] . '" src="' . $cartplog['thumb'] . '" alt="" border="0" />'; } else { $cartplog['thumb'] = '<img style="' . $vbulletin->options['cartplog_thumbcss'] . '" src="../' . $vbulletin->options['cleargifurl'] . '" alt="" border="0" />'; } eval('$cartplog[\'history_items\'] .= "' . fetch_template('cartplog_history_item') . '";'); } eval('$cartplog[\'history_list\'] .= "' . fetch_template('cartplog_history_list') . '";'); } $db->free_result($cartplog_transaction_infos); if (!$cartplog['history_list']) { $cartplog['history_list'] = '<tr><td class="alt1">' . $vbphrase['none'] . '</td></tr>'; } $navbits = array(); $navbits['cartplog.php' . $vbulletin->session->vars['sessionurl_q']] = htmlspecialchars_uni($vbphrase['cartplog']); $navbits[''] = htmlspecialchars_uni($vbphrase['cartplog_view_history']); $navbits = construct_navbits($navbits); eval('$navbar = "' . fetch_template('navbar') . '";'); eval('print_output("' . fetch_template('cartplog_view_history') . '");'); } if ($_REQUEST['do'] == 'viewitem') { $vbulletin->input->clean_array_gpc('r', array( 'cartplogproductid' => TYPE_UINT, )); $cartplog['productid'] = $vbulletin->GPC['cartplogproductid']; $cartplog_product_check = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "cartplog_products WHERE productid = " . intval($cartplog['productid']) . " "); if ($cartplog_product_check) { $cartplog['product_productid'] = intval($cartplog_product_check['productid']); $cartplog['product_thumb'] = strval($cartplog_product_check['thumb']); $cartplog['product_title'] = htmlspecialchars_uni($cartplog_product_check['title']); $cartplog['product_description'] = strval($cartplog_product_check['description']); $cartplog['product_price'] = round(floatval($cartplog_product_check['price']), 2); $cartplog['product_options'] = ''; $cartplog_product_options = array_map('trim', unserialize($cartplog_product_check['options'])); if (!is_array($cartplog_product_options)) { $cartplog_product_options = array(); } foreach($cartplog_product_options AS $cartplog_options_key => $cartplog_options_title) { if (vbstrlen($cartplog_options_title)) { $cartplog['options_title'] = htmlspecialchars_uni($cartplog_options_title); $cartplog['product_options'] .= '<option value="' . $cartplog['options_title'] . '">' . $cartplog['options_title'] . '</option>'; $cartplog['product_options'] .= "\n"; } } if ($cartplog['product_options']) { $cartplog['product_options'] = '<select name="cartplogoptions">' . $cartplog['product_options'] . '</select>'; } $navbits = array(); $navbits['cartplog.php' . $vbulletin->session->vars['sessionurl_q']] = htmlspecialchars_uni($vbphrase['cartplog']); $navbits[''] = htmlspecialchars_uni($vbphrase['cartplog_view_item']); $navbits = construct_navbits($navbits); eval('$navbar = "' . fetch_template('navbar') . '";'); eval('print_output("' . fetch_template('cartplog_view_item') . '");'); } else { $cartplog_url = 'cartplog.php?' . $vbulletin->session->vars['sessionurl'] . 'do=viewindex'; exec_header_redirect($cartplog_url); exit(); } } if ($_REQUEST['do'] == 'additem') { $vbulletin->input->clean_array_gpc('r', array( 'cartplogproductid' => TYPE_UINT, 'cartplogoptions' => TYPE_STR, 'cartplogsubmit' => TYPE_STR )); $cartplog['productid'] = $vbulletin->GPC['cartplogproductid']; $cartplog['options'] = $vbulletin->GPC['cartplogoptions']; $cartplog['submit'] = $vbulletin->GPC['cartplogsubmit']; if ($cartplog['submit'] == $vbphrase['cartplog_continue_shopping']) { $cartplog_url = 'cartplog.php?' . $vbulletin->session->vars['sessionurl'] . 'do=viewindex'; exec_header_redirect($cartplog_url); exit(); } $cartplog_product_check = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "cartplog_products WHERE productid = " . intval($cartplog['productid']) . " "); if ($cartplog_product_check) { if ($cartplog_product_check['options']) { $cartplog_product_check['options'] = array_map('trim', unserialize($cartplog_product_check['options'])); if (is_array($cartplog_product_check['options']) && vbstrlen($cartplog['options'])) { $cartplog_search_key = array_search($cartplog['options'], $cartplog_product_check['options']); if ($cartplog_search_key === false) { $cartplog['options'] = ''; } } else { $cartplog['options'] = ''; } } else { $cartplog['options'] = ''; } $cartplog_basket_check = $db->query_first("SELECT products FROM " . TABLE_PREFIX . "cartplog_sessions WHERE userid = " . intval($vbulletin->userinfo['userid']) . " AND sessionid = '" . $db->escape_string($cartplog['cookie']) . "' "); if ($cartplog_basket_check['products']) { $cartplog_basket_check['products'] = unserialize($cartplog_basket_check['products']); if (!is_array($cartplog_basket_check['products'])) { $cartplog_basket_check['products'] = array(); } if ($cartplog_basket_check['products'][$cartplog['productid']]) { $cartplog_basket_check['products'][$cartplog['productid']]['quantity'] ++; if (vbstrlen($cartplog_basket_check['products'][$cartplog['productid']]['options']) && vbstrlen($cartplog['options'])) { $cartplog_basket_check['products'][$cartplog['productid']]['options'] .= ', ' . $cartplog['options']; } else if (vbstrlen($cartplog['options'])) { $cartplog_basket_check['products'][$cartplog['productid']]['options'] = $cartplog['options']; } } else { $cartplog_basket_check['products'][$cartplog['productid']] = array( 'quantity' => 1, 'thumb' => $cartplog_product_check['thumb'], 'title' => $cartplog_product_check['title'], 'price' => $cartplog_product_check['price'], 'options' => $cartplog['options'] ); } $cartplog_basket_check['products'] = serialize($cartplog_basket_check['products']); $db->query_write("UPDATE " . TABLE_PREFIX . "cartplog_sessions SET products = '" . $db->escape_string($cartplog_basket_check['products']) . "' WHERE userid = " . intval($vbulletin->userinfo['userid']) . " AND sessionid = '" . $db->escape_string($cartplog['cookie']) . "' "); } } $cartplog_url = 'cartplog.php?' . $vbulletin->session->vars['sessionurl'] . 'do=viewcart'; exec_header_redirect($cartplog_url); exit(); } if ($_REQUEST['do'] == 'removeitem') { $vbulletin->input->clean_array_gpc('r', array( 'cartplogproductid' => TYPE_UINT )); $cartplog['productid'] = $vbulletin->GPC['cartplogproductid']; $cartplog_basket_check = $db->query_first("SELECT products FROM " . TABLE_PREFIX . "cartplog_sessions WHERE userid = " . intval($vbulletin->userinfo['userid']) . " AND sessionid = '" . $db->escape_string($cartplog['cookie']) . "' "); if ($cartplog_basket_check['products']) { $cartplog_basket_check['products'] = unserialize($cartplog_basket_check['products']); if (!is_array($cartplog_basket_check['products'])) { $cartplog_basket_check['products'] = array(); } unset($cartplog_basket_check['products'][$cartplog['productid']]); $cartplog_basket_check['products'] = serialize($cartplog_basket_check['products']); $db->query_write("UPDATE " . TABLE_PREFIX . "cartplog_sessions SET products = '" . $db->escape_string($cartplog_basket_check['products']) . "' WHERE userid = " . intval($vbulletin->userinfo['userid']) . " AND sessionid = '" . $db->escape_string($cartplog['cookie']) . "' "); } $cartplog_url = 'cartplog.php?' . $vbulletin->session->vars['sessionurl'] . 'do=viewcart'; exec_header_redirect($cartplog_url); exit(); } if ($_REQUEST['do'] == 'updatequantity') { $vbulletin->input->clean_array_gpc('r', array( 'cartplogquantity' => TYPE_ARRAY, 'cartplogsubmit' => TYPE_STR )); $cartplog['quantity'] = $vbulletin->GPC['cartplogquantity']; $cartplog['submit'] = $vbulletin->GPC['cartplogsubmit']; if ($cartplog['submit'] == $vbphrase['cartplog_continue_shopping']) { $cartplog_url = 'cartplog.php?' . $vbulletin->session->vars['sessionurl'] . 'do=viewindex'; exec_header_redirect($cartplog_url); exit(); } if ($cartplog['submit'] == $vbphrase['cartplog_checkout']) { $cartplog_url = 'cartplog.php?' . $vbulletin->session->vars['sessionurl'] . 'do=checkout'; exec_header_redirect($cartplog_url); exit(); } $cartplog_basket_check = $db->query_first("SELECT products FROM " . TABLE_PREFIX . "cartplog_sessions WHERE userid = " . intval($vbulletin->userinfo['userid']) . " AND sessionid = '" . $db->escape_string($cartplog['cookie']) . "' "); if ($cartplog_basket_check['products']) { $cartplog_basket_check['products'] = unserialize($cartplog_basket_check['products']); if (!is_array($cartplog_basket_check['products'])) { $cartplog_basket_check['products'] = array(); } if (!empty($cartplog_basket_check['products'])) { foreach($cartplog['quantity'] AS $cartplog_basket_productid => $cartplog_basket_quantity) { $cartplog_basket_productid = max(0, intval($cartplog_basket_productid)); $cartplog_basket_quantity = max(0, intval($cartplog_basket_quantity)); if (!$cartplog_basket_quantity) { unset($cartplog_basket_check['products'][$cartplog_basket_productid]); } else { $cartplog_basket_check['products'][$cartplog_basket_productid]['quantity'] = $cartplog_basket_quantity; } } if (empty($cartplog_basket_check['products'])) { $cartplog_basket_check['products'] = array(); } $cartplog_basket_check['products'] = serialize($cartplog_basket_check['products']); $db->query_write("UPDATE " . TABLE_PREFIX . "cartplog_sessions SET products = '" . $db->escape_string($cartplog_basket_check['products']) . "' WHERE userid = " . intval($vbulletin->userinfo['userid']) . " AND sessionid = '" . $db->escape_string($cartplog['cookie']) . "' "); } } $cartplog_url = 'cartplog.php?' . $vbulletin->session->vars['sessionurl'] . 'do=viewcart'; exec_header_redirect($cartplog_url); exit(); } if ($_REQUEST['do'] == 'postback') { $cartplog_paypal_postback = 'cmd=_notify-validate'; foreach($_POST AS $cartplog_paypal_key => $cartplog_paypal_value) { if (!empty($cartplog_paypal_value)) { $cartplog_paypal_postback .= '&' . $cartplog_paypal_key . '=' . urlencode($cartplog_paypal_value); } } $cartplog_paypal_result = false; $cartplog_used_curl = false; if (function_exists('curl_init') && $cartplog_paypal_curl = curl_init()) { curl_setopt($cartplog_paypal_curl, CURLOPT_URL, 'http://www.paypal.com/cgi-bin/webscr'); curl_setopt($cartplog_paypal_curl, CURLOPT_POST, true); // for x-www-form-urlencoded curl_setopt($cartplog_paypal_curl, CURLOPT_POSTFIELDSIZE, strlen($cartplog_paypal_postback)); curl_setopt($cartplog_paypal_curl, CURLOPT_POSTFIELDS, $cartplog_paypal_postback); curl_setopt($cartplog_paypal_curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($cartplog_paypal_curl, CURLOPT_TIMEOUT, 30); $cartplog_paypal_result = curl_exec($cartplog_paypal_curl); // retuns false on failure curl_close($cartplog_paypal_curl); if ($cartplog_paypal_result !== false) { $cartplog_used_curl = true; } } if (!$cartplog_used_curl) { $cartplog_paypal_header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $cartplog_paypal_header .= "Host: www.paypal.com\r\n"; $cartplog_paypal_header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $cartplog_paypal_header .= "Content-Length: " . strlen($cartplog_paypal_postback) . "\r\n\r\n"; $cartplog_paypal_header .= $cartplog_paypal_postback; $cartplog_paypal_errno = $cartplog_paypal_errstr = ''; if ($cartplog_paypal_fsockopen = fsockopen('www.paypal.com', 80, $cartplog_paypal_errno, $cartplog_paypal_errstr, 30)) { stream_set_timeout($cartplog_paypal_fsockopen, 30); fwrite($cartplog_paypal_fsockopen, $cartplog_paypal_header); while (!feof($cartplog_paypal_fsockopen)) { $cartplog_paypal_result = fgets($cartplog_paypal_fsockopen, 1024); } fclose($cartplog_paypal_fsockopen); } } if ($cartplog_paypal_result == 'VERIFIED') { $vbulletin->input->clean_array_gpc('p', array( 'item_number1' => TYPE_NOHTML, 'business' => TYPE_NOHTML, 'receiver_email' => TYPE_NOHTML, 'mc_gross' => TYPE_NUM, 'payment_status' => TYPE_NOHTML, 'txn_id' => TYPE_NOHTML, 'txn_type' => TYPE_NOHTML )); $cartplog['item_number'] = $vbulletin->GPC['item_number1']; $cartplog['business'] = $vbulletin->GPC['business']; $cartplog['receiver_email'] = $vbulletin->GPC['receiver_email']; $cartplog['mc_gross'] = $vbulletin->GPC['mc_gross']; $cartplog['payment_status'] = $vbulletin->GPC['payment_status']; $cartplog['txn_id'] = $vbulletin->GPC['txn_id']; $cartplog['txn_type'] = $vbulletin->GPC['txn_type']; $cartplog_paypal_api = $db->query_first("SELECT settings FROM " . TABLE_PREFIX . "paymentapi WHERE classname = 'paypal' "); $cartplog['ppemail'] = ''; $cartplog['primaryemail'] = ''; $cartplog_paypal_api['settings'] = unserialize($cartplog_paypal_api['settings']); if (is_array($cartplog_paypal_api['settings'])) { foreach($cartplog_paypal_api['settings'] AS $cartplog_paypal_api_title => $cartplog_paypal_api_array) { if ($cartplog_paypal_api_title == 'ppemail') { $cartplog['ppemail'] = strtolower($cartplog_paypal_api_array['value']); } if ($cartplog_paypal_api_title == 'primaryemail') { $cartplog['primaryemail'] = strtolower($cartplog_paypal_api_array['value']); } } } if ($vbulletin->GPC['business'] == $cartplog['ppemail'] || $vbulletin->GPC['receiver_email'] == $cartplog['primaryemail']) { $cartplog_basket_check = $db->query_first("SELECT cartplog_sessions.*, user.username, user.userid FROM " . TABLE_PREFIX . "cartplog_sessions AS cartplog_sessions, " . TABLE_PREFIX . "user AS user WHERE cartplog_sessions.userid = user.userid AND cartplog_sessions.sessionid = '" . $db->escape_string($cartplog['item_number']) . "' "); $cartplog['sessionid'] = strval($cartplog_basket_check['sessionid']); $cartplog['userid'] = intval($cartplog_basket_check['userid']); $cartplog['products'] = strval($cartplog_basket_check['products']); $cartplog['username'] = strval($cartplog_basket_check['username']); $cartplog['basket_total'] = 0; $cartplog['popular'] = array(); $cartplog['products2'] = ''; if ($cartplog_basket_check['products']) { $cartplog_basket_check['products'] = unserialize($cartplog['products']); if (!is_array($cartplog_basket_check['products'])) { $cartplog_basket_check['products'] = array(); } foreach($cartplog_basket_check['products'] AS $cartplog_basket_productid => $cartplog_basket_array) { $cartplog['basket_total'] += round(intval($cartplog_basket_array['quantity']) * floatval($cartplog_basket_array['price']), 2); $cartplog['popular'][] = intval($cartplog_basket_productid); if (!vbstrlen($cartplog_basket_array['options'])) { $cartplog_basket_array['options'] = $vbphrase['none']; } $cartplog['products2'] .= "\n\t" . $vbphrase['cartplog_quantity'] . ": " . $cartplog_basket_array['quantity'] . "\n\t" . $vbphrase['title'] . ": " . $cartplog_basket_array['title'] . "\n\t" . $vbphrase['options'] . ": " . $cartplog_basket_array['options'] . "\n"; } } if (!$cartplog['products2']) { $cartplog['products2'] = $vbphrase['cartplog_unknown']; } $cartplog['basket_total'] = number_format($cartplog['basket_total'], 2, '.', ''); $cartplog['mc_gross'] = number_format(floatval($cartplog['mc_gross']), 2, '.', ''); $cartplog_transaction_info = $db->query_first("SELECT txnid FROM " . TABLE_PREFIX . "cartplog_transactions WHERE txnid = '" . $db->escape_string($cartplog['txn_id']) . "' AND class = 'paypal' "); if (!$cartplog_transaction_info) { $db->query_write("INSERT INTO " . TABLE_PREFIX . "cartplog_transactions (sessionid, txnid, userid, total, status, class, dateline, products) VALUES ( '" . $db->escape_string($cartplog['sessionid']) . "', '" . $db->escape_string($cartplog['txn_id']) . "', " . intval($cartplog['userid']) . ", " . floatval($cartplog['mc_gross']) . ", '" . $db->escape_string($cartplog['payment_status']) . "', 'paypal', " . intval(TIMENOW) . ", '" . $db->escape_string($cartplog['products']) . "' ) "); $db->query_write("UPDATE " . TABLE_PREFIX . "cartplog_sessions SET completed = 1 WHERE userid = " . intval($cartplog['userid']) . " AND sessionid = '" . $db->escape_string($cartplog['sessionid']) . "' "); } $cartplog['products'] = $cartplog['products2']; $cartplog_phrase = 'cartplog_payment_unknown'; if ($cartplog['txn_type'] == 'cart' && $cartplog['payment_status'] == 'Completed' && $cartplog['basket_total'] == $cartplog['mc_gross']) { $cartplog_phrase = 'cartplog_payment_received'; if (!empty($cartplog['popular'])) { $db->query_write("UPDATE " . TABLE_PREFIX . "cartplog_products SET sales = sales + 1 WHERE productid IN (" . implode(',', $cartplog['popular']) . ") "); } } else if ($cartplog['payment_status'] == 'Refunded' || $cartplog['payment_status'] == 'Reversed') { $cartplog_phrase = 'cartplog_payment_reversed'; } if ($vbulletin->options['paymentemail']) { if (!$vbphrase) { $vbphrase = init_language(); } $cartplog['username'] = unhtmlspecialchars($cartplog['username']); $cartplog_subject = $cartplog_message = ''; eval(fetch_email_phrases($cartplog_phrase, 0, '', 'cartplog_')); $cartplog_emails = explode(' ', $vbulletin->options['paymentemail']); foreach($cartplog_emails AS $cartplog_email) { $cartplog_email = trim($cartplog_email); if ($cartplog_email) { vbmail($cartplog_email, $cartplog_subject, $cartplog_message, true); } } } if (SAPI_NAME == 'cgi' OR SAPI_NAME == 'cgi-fcgi') { header('Status: 200 OK'); } else { header('HTTP/1.1 200 OK'); } } } } ?> thank you aebstract. Can you point me in the direction now? Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451562 Share on other sites More sharing options...
aebstract Posted January 28, 2008 Share Posted January 28, 2008 Looks like this to me: $cartplog_product_infos = $db->query_read("SELECT productid, catid, thumb, title, price FROM " . TABLE_PREFIX . "cartplog_products WHERE sales = " . intval($cartplog_max_salescnt) . " "); Located just before the code you posted in the first post. Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451567 Share on other sites More sharing options...
dcuellar Posted January 28, 2008 Author Share Posted January 28, 2008 So this is what I need to do...in red? $cartplog_product_infos = $db->query_read("SELECT productid, catid, thumb, title, price FROM " . TABLE_PREFIX . "cartplog_products WHERE sales = " . intval($cartplog_max_salescnt) . " ")[color=red]LIMIT 10[/color]; Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451571 Share on other sites More sharing options...
duclet Posted January 28, 2008 Share Posted January 28, 2008 $cartplog_product_infos = $db->query_read("SELECT productid, catid, thumb, title, price FROM " . TABLE_PREFIX . "cartplog_products WHERE sales = " . intval($cartplog_max_salescnt) . " LIMIT 10"); Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451574 Share on other sites More sharing options...
dcuellar Posted January 28, 2008 Author Share Posted January 28, 2008 Man! You guys are awesome. Working just fine!!! Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451577 Share on other sites More sharing options...
dcuellar Posted January 28, 2008 Author Share Posted January 28, 2008 one more thing... That worked, but now the area to the side of the popular products column was also set to an unlimited amount. I'm trying to find where to put "LIMIT 15". Here is the code. Let me know if it is not in there. // ######################## START MAIN SCRIPT ############################# if ($_REQUEST['do'] == 'viewindex') { // full table scan but no one should have millions of products $cartplog_product_infos = $db->query_read("SELECT productid, catid, thumb, title, price, sales FROM " . TABLE_PREFIX . "cartplog_products ORDER BY RAND() "); $cartplog['product_list'] = ''; $cartplog_count = 0; $cartplog_max_productid = 0; $cartplog_max_salescnt = 0; while ($cartplog_product_info = $db->fetch_array($cartplog_product_infos)) { $cartplog_count ++; $cartplog['product_productid'] = intval($cartplog_product_info['productid']); $cartplog['product_catid'] = intval($cartplog_product_info['catid']); $cartplog['product_thumb'] = strval($cartplog_product_info['thumb']); $cartplog['product_title'] = htmlspecialchars_uni($cartplog_product_info['title']); $cartplog['product_price'] = round(floatval($cartplog_product_info['price']), 2); $cartplog['product_sales'] = intval($cartplog_product_info['sales']); $cartplog_max_productid = max($cartplog_max_productid, $cartplog['product_productid']); $cartplog_max_salescnt = max($cartplog_max_salescnt, $cartplog['product_sales']); eval('$cartplog[\'product_list\'] .= "' . fetch_template('cartplog_product_item') . '";'); if ($cartplog_count % 3 == 0) { $cartplog['product_list'] .= '</tr><tr>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451735 Share on other sites More sharing options...
dcuellar Posted January 28, 2008 Author Share Posted January 28, 2008 got it... thanks anyways. Quote Link to comment https://forums.phpfreaks.com/topic/88241-solved-setting-a-limit/#findComment-451739 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.