Executes a SQL query and returns the value from the SQL result.
If the SQL result contains more than one column and/or more than one row, this function returns the value in the column and row specified.
If $query is null, this function returns the value in the specified column and row from the previous SQL result.
public get_var ( string | null $query = null, integer $x, integer $y ) : string | null | ||
$query | string | null | Optional. SQL query. Defaults to null, use the result from the previous query. |
$x | integer | Optional. Column of value to return. Indexed from 0. |
$y | integer | Optional. Row of value to return. Indexed from 0. |
return | string | null | Database query result (as string), or null on failure |
function musicmate_get_store_products($product_cnt = 1) { //Connect to the OSCommerce database $storedatabase = new wpdb(get_option('oscimp_dbuser'), get_option('oscimp_dbpwd'), get_option('oscimp_dbname'), get_option('oscimp_dbhost')); $prodVal = ''; for ($i = 0; $i < $product_cnt; $i++) { //Get a random product $product_count = 0; while ($product_count == 0) { $product_id = rand(0, 30); $product_count = $storedatabase->get_var("SELECT COUNT(*) FROM products WHERE products_id={$product_id} AND products_status=1"); } //Get product image, name and URL $product_image = $storedatabase->get_var("SELECT products_image FROM products WHERE products_id={$product_id}"); $product_name = $storedatabase->get_var("SELECT products_name FROM products_description WHERE products_id={$product_id}"); $store_url = get_option('oscimp_store_url'); $image_folder = get_option('oscimp_prod_img_folder'); //Build the HTML code $prodVal .= '<div class="store_product">'; $prodVal .= '<a href="' . $store_url . 'product_info.php?products_id=' . $product_id . '"><img src="' . $image_folder . $product_image . '" /></a><br />'; $prodVal .= '<a href="' . $store_url . 'product_info.php?products_id=' . $product_id . '">' . $product_name . '</a>'; $prodVal .= '</div>'; } return $prodVal; }
function global_site_search_page_setup() { $page_id = get_option('global_site_search_page', false); if (empty($page_id) || !is_object(get_post($page_id)) && is_super_admin()) { // a page hasn't been set - so check if there is already one with the base name $page_id = $this->db->get_var($this->db->prepare("SELECT ID FROM {$this->db->posts} WHERE post_name = %s AND post_type = 'page'", $this->global_site_search_base)); if (empty($page_id)) { // Doesn't exist so create the page $page_id = wp_insert_post(array("post_content" => '', "post_title" => __('Site Search', 'globalsitesearch'), "post_excerpt" => '', "post_status" => 'publish', "comment_status" => 'closed', "ping_status" => 'closed', "post_name" => $this->global_site_search_base, "post_type" => 'page')); flush_rewrite_rules(); } update_option('global_site_search_page', $page_id); } }
/** * @param int $limit * @return mixed */ public function getTopFailedLogins($limit = 10) { $interval = 'UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 7 day))'; switch (wfConfig::get('email_summary_interval', 'weekly')) { case 'daily': $interval = 'UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 1 day))'; break; case 'monthly': $interval = 'UNIX_TIMESTAMP(DATE_SUB(NOW(), interval 1 month))'; break; } $failedLogins = $this->db->get_results($this->db->prepare(<<<SQL SELECT wfl.*, sum(wfl.fail) as fail_count FROM {$this->db->base_prefix}wfLogins wfl WHERE wfl.fail = 1 AND wfl.ctime > {$interval} GROUP BY wfl.username ORDER BY fail_count DESC LIMIT %d SQL , $limit)); foreach ($failedLogins as &$login) { $exists = $this->db->get_var($this->db->prepare(<<<SQL SELECT !ISNULL(ID) FROM {$this->db->base_prefix}users WHERE user_login = '******' OR user_email = '%s' SQL , $login->username, $login->username)); $login->is_valid_user = $exists; } return $failedLogins; }
private function select_translation_id($where, $prepare_args) { $this->translation_id = $this->wpdb->get_var("SELECT translation_id FROM {$this->wpdb->prefix}{$this->table}\n\t\t\t WHERE" . $this->wpdb->prepare($where, $prepare_args) . " LIMIT 1"); if (!$this->translation_id) { throw new InvalidArgumentException('No translation entry found for query: ' . serialize($where) . serialize($prepare_args)); } }
/** * Build login cookie. */ function build_blog_cookie($action = 'login', $userblog_id = '') { global $blog_id; if ($action == '') { $action = 'login'; } $url = false; if (class_exists('domain_map') && defined('DOMAIN_MAPPING')) { $domain = $this->db->get_var("SELECT domain FROM {$this->db->dmtable} WHERE blog_id = '{$userblog_id}' ORDER BY id LIMIT 1"); if ($domain) { $dom = str_replace('.', '', $domain); $url = 'http://' . $domain . '/'; } } else { $domains = $this->db->get_row("SELECT domain, path FROM {$this->db->blogs} WHERE blog_id = '{$userblog_id}' LIMIT 1"); $dom = str_replace('.', '', $domains->domain); $url = 'http://' . $domains->domain . $domains->path; } if ($url) { $key = get_site_option("multi_domains_cross_domain_{$dom}", array()); $user_id = get_current_user_id(); if (!isset($key[$user_id]['action']) || isset($key[$user_id]['action']) && $key[$user_id]['action'] !== $action) { $key[$user_id] = array('domain' => $url, 'action' => $action); update_site_option("multi_domains_cross_domain_{$dom}", $key); } $hash = md5(AUTH_KEY . 'multi_domains'); if ($blog_id !== $userblog_id && 'login' == $action) { // Removing transient check echo '<link rel="stylesheet" href="' . $url . $hash . '.css?build=' . date("Ymd", strtotime('-24 days')) . '&id=' . $user_id . '" type="text/css" media="screen" />'; set_transient("multi_domains_{$dom}_{$user_id}", 'add', 60 * 15); } } }
function site_get_avatar($avatar, $id_or_email, $size, $default, $alt) { $email = ''; if (is_numeric($id_or_email)) { $id = (int) $id_or_email; $user = get_userdata($id); if ($user) { $email = $user->user_email; } } elseif (is_object($id_or_email)) { $email = $id_or_email->comment_author_email; } $forum_db = ''; $img_folder = ''; // No trailing slash $img_path = $img_folder . '/image.php?u='; $my_wpdb = new wpdb(DB_USER, DB_PASSWORD, $forum_db, DB_HOST); $myrows = $my_wpdb->get_var($my_wpdb->prepare("SELECT userid\n FROM " . $forum_db . ".vb_user\n WHERE email = %s LIMIT 1", array($email))); if ($myrows != '') { $img = $img_path . $myrows; } elseif ($avatar) { return $avatar; } else { $img = $default; } $my_avatar = '<img src="' . $img . '" alt="' . $alt . '" height="' . $size . '" width="' . $size . '" class="avatar avatar-50 photo grav-hashed grav-hijack" />'; return $my_avatar; }
/** * Execute the query, with the current variables. * * @since 3.1.0 */ public function query() { $qv =& $this->query_vars; $this->request = "SELECT {$this->query_fields} {$this->query_from} {$this->query_where} {$this->query_orderby} {$this->query_limit}"; if (is_array($qv['fields']) || 'all' == $qv['fields']) { $this->results = $this->db->get_results($this->request); } else { $this->results = $this->db->get_col($this->request); } /** * Filters SELECT FOUND_ROWS() query for the current WP_User_Query instance. * * @since 3.2.0 * * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. */ if (isset($qv['count_total']) && $qv['count_total']) { $this->total_users = $this->db->get_var(apply_filters('found_users_query', 'SELECT FOUND_ROWS()')); } if (!$this->results) { return; } if ('all_with_meta' == $qv['fields']) { cache_users($this->results); $r = array(); foreach ($this->results as $userid) { $r[$userid] = new WP_User($userid, '', $qv['blog_id']); } $this->results = $r; } elseif ('all' == $qv['fields']) { foreach ($this->results as $key => $user) { $this->results[$key] = new WP_User($user, '', $qv['blog_id']); } } }
/** * @param string $iso Something like de_AT * * @param string $field the field which should be queried * @return mixed */ public function get_lang_data_by_iso($iso, $field = 'native_name') { $iso = str_replace('_', '-', $iso); $query = $this->wpdb->prepare("SELECT `{$field}`\n\t\t\tFROM `{$this->table_name}`\n\t\t\tWHERE `http_name` = " . "%s LIMIT 1", $iso); $result = $this->wpdb->get_var($query); $return = NULL === $result ? '' : $result; return $return; }
/** * @param array $args * @param string $output_type * @return int|mixed */ public function find($args, $output_type = OBJECT) { $args = wp_parse_args($args, array('select' => '*', 'offset' => 0, 'limit' => 1, 'orderby' => 'id', 'order' => 'DESC', 'email' => '', 'method' => '', 'datetime_after' => '', 'datetime_before' => '', 'include_errors' => true)); $where = array(); $params = array(); // build general select from query $query = sprintf("SELECT %s FROM `%s`", $args['select'], $this->table_name); // add email to WHERE clause if ('' !== $args['email']) { $where[] = 'email LIKE %s'; $params[] = '%%' . $this->db->esc_like($args['email']) . '%%'; } // add method to WHERE clause if ('' !== $args['method']) { $where[] = 'method = %s'; $params[] = $args['method']; } // add datetime to WHERE clause if ('' !== $args['datetime_after']) { $where[] = 'datetime >= %s'; $params[] = $args['datetime_after']; } if ('' !== $args['datetime_before']) { $where[] = 'datetime <= %s'; $params[] = $args['datetime_before']; } if (!$args['include_errors']) { $where[] = 'success = %d'; $params[] = 1; } // add where parameters if (count($where) > 0) { $query .= ' WHERE ' . implode(' AND ', $where); } // prepare parameters if (!empty($params)) { $query = $this->db->prepare($query, $params); } // return result count if ($args['select'] === 'COUNT(*)') { return (int) $this->db->get_var($query); } // return single row if ($args['limit'] === 1) { $query .= ' LIMIT 1'; return $this->db->get_row($query); } // perform rest of query $args['limit'] = absint($args['limit']); $args['offset'] = absint($args['offset']); $args['orderby'] = preg_replace("/[^a-zA-Z]/", "", $args['orderby']); $args['order'] = preg_replace("/[^a-zA-Z]/", "", $args['order']); // add ORDER BY, OFFSET and LIMIT to SQL $query .= sprintf(' ORDER BY `%s` %s LIMIT %d, %d', $args['orderby'], $args['order'], $args['offset'], $args['limit']); return $this->db->get_results($query, $output_type); }
/** * Records transaction into database. * * @access protected * @param type $user_id * @param type $sub_id * @param type $amount * @param type $currency * @param type $timestamp * @param type $paypal_ID * @param type $status * @param type $note */ protected function _record_transaction($user_id, $sub_id, $amount, $currency, $timestamp, $paypal_ID, $status, $note) { $data = array('transaction_subscription_ID' => $sub_id, 'transaction_user_ID' => $user_id, 'transaction_paypal_ID' => $paypal_ID, 'transaction_stamp' => $timestamp, 'transaction_currency' => $currency, 'transaction_status' => $status, 'transaction_total_amount' => (int) round($amount * 100), 'transaction_note' => $note, 'transaction_gateway' => $this->gateway); $existing_id = $this->db->get_var($this->db->prepare("SELECT transaction_ID FROM " . MEMBERSHIP_TABLE_SUBSCRIPTION_TRANSACTION . " WHERE transaction_paypal_ID = %s LIMIT 1", $paypal_ID)); if (!empty($existing_id)) { $this->db->update(MEMBERSHIP_TABLE_SUBSCRIPTION_TRANSACTION, $data, array('transaction_ID' => $existing_id)); } else { $this->db->insert(MEMBERSHIP_TABLE_SUBSCRIPTION_TRANSACTION, $data); } }
function get_meta($key, $default = false) { $sql = $this->db->prepare('SELECT meta_value FROM ' . MEMBERSHIP_TABLE_SUBSCRIPTION_META . ' WHERE meta_key = %s AND sub_id = %d', $key, $this->id); $row = $this->db->get_var($sql); if (empty($row)) { return $default; } else { return $row; } }
private function fillParentId($metaEntityName, $where, $id) { $entityInfo = $this->dbSchemaInfo->getEntityInfo($metaEntityName); $parentReference = $entityInfo->parentReference; $parent = $entityInfo->references[$parentReference]; $vpIdTable = $this->dbSchemaInfo->getPrefixedTableName('vp_id'); $entityTable = $this->dbSchemaInfo->getPrefixedTableName($metaEntityName); $parentTable = $this->dbSchemaInfo->getTableName($parent); $idColumnName = $this->dbSchemaInfo->getEntityInfo($metaEntityName)->idColumnName; $where["vp_{$parentReference}"] = $this->database->get_var("SELECT HEX(vp_id) FROM {$vpIdTable} WHERE `table` = '{$parentTable}' AND ID = (SELECT {$parentReference} FROM {$entityTable} WHERE {$idColumnName} = {$id})"); return $where; }
/** * Get the primary domain if domain mapping is active * * @return string */ private function get_mapped_domain() { if (empty($this->wpdb->dmtable)) { return ''; } $sql = 'SELECT domain FROM ' . $this->wpdb->dmtable . ' WHERE active = 1 AND blog_id = %s LIMIT 1'; $sql = $this->wpdb->prepare($sql, get_current_blog_id()); $domain = $this->wpdb->get_var($sql); if ('' === $domain) { return ''; } return (is_ssl() ? 'https://' : 'http://') . $domain; }
/** * Checks whether or not a record doesn't exist in the database. * * @since 1.0.0 * * @access public * @param string $table The table name. * @param array $criteria The array of conditions. */ public function dontSeeInDatabase($table, $criteria = array()) { $query = $this->_prepareQuery($table, 'count(*)', $criteria); $this->debugSection('Query', $query); $suppress_errors = $this->_wpdb->suppress_errors(true); $res = $this->_wpdb->get_var($query); $this->_wpdb->suppress_errors($suppress_errors); if (!empty($this->_wpdb->last_error)) { $this->fail('Database error: ' . $this->_wpdb->last_error); return; } $this->assertLessThan(1, $res, 'Matching records found'); }
/** * Populates found_networks and max_num_pages properties for the current query * if the limit clause was used. * * @since 4.6.0 * @access private */ private function set_found_networks() { if ($this->query_vars['number'] && !$this->query_vars['no_found_rows']) { /** * Filters the query used to retrieve found network count. * * @since 4.6.0 * * @param string $found_networks_query SQL query. Default 'SELECT FOUND_ROWS()'. * @param WP_Network_Query $network_query The `WP_Network_Query` instance. */ $found_networks_query = apply_filters('found_networks_query', 'SELECT FOUND_ROWS()', $this); $this->found_networks = (int) $this->db->get_var($found_networks_query); } }
/** * @param array $args * * @return int|mixed */ public function find($args = array()) { $args = wp_parse_args($args, array('select' => '*', 'email' => '', 'method' => '', 'type' => '', 'limit' => 1, 'offset' => 0, 'orderby' => 'id', 'order' => 'DESC')); $where = array(); $params = array(); // build general select from query $query = sprintf("SELECT %s FROM `%s`", $args['select'], $this->table_name); // add email to WHERE clause if ('' !== $args['email']) { $where[] = 'email LIKE %s'; $params[] = '%%' . $this->db->esc_like($args['email']) . '%%'; } // add method to WHERE clause if ('' !== $args['method']) { $where[] = 'method = %s'; $params[] = $args['method']; } // add where parameters if (count($where) > 0) { $query .= ' WHERE ' . implode(' AND ', $where); } // prepare parameters if (!empty($params)) { $query = $this->db->prepare($query, $params); } // return result count if ($args['select'] === 'COUNT(*)') { $query .= ' LIMIT 1'; return (int) $this->db->get_var($query); } // return single row if ($args['limit'] === 1) { $query .= ' LIMIT 1'; return $this->db->get_row($query); } // perform rest of query $args['limit'] = absint($args['limit']); $args['offset'] = absint($args['offset']); $order_by = sanitize_key($args['orderby']) . ' ' . strtoupper(sanitize_key($args['order'])); // add ORDER BY, OFFSET and LIMIT to SQL $query .= sprintf(' ORDER BY %s LIMIT %d, %d', $order_by, $args['offset'], $args['limit']); return $this->db->get_results($query); }
/** * Load the localization * * @since 0.1 * @uses load_plugin_textdomain, plugin_basename * @param Mlp_Db_Schema_Interface $languages * @return void */ private function import_active_languages(Mlp_Db_Schema_Interface $languages) { // get active languages $mlp_settings = get_site_option('inpsyde_multilingual'); if (empty($mlp_settings)) { return; } $table = $languages->get_table_name(); $sql = 'SELECT ID FROM ' . $table . 'WHERE wp_locale = %s OR iso_639_1 = %s'; foreach ($mlp_settings as $mlp_site) { $text = $mlp_site['text'] != '' ? $mlp_site['text'] : $mlp_site['lang']; $query = $this->wpdb->prepare($sql, $mlp_site['lang'], $mlp_site['lang']); $lang_id = $this->wpdb->get_var($query); // language not found -> insert if (empty($lang_id)) { // @todo add custom name $this->wpdb->insert($table, array('english_name' => $text, 'wp_locale' => $mlp_site['lang'], 'http_name' => str_replace('_', '-', $mlp_site['lang']))); } else { $this->wpdb->update($table, array('priority' => 10), array('ID' => $lang_id)); } } }
protected function actionUnlicenseSite($productSlug, $licenseKey = null, $token = null) { $this->requireRequestMethod('POST'); $license = $this->validateLicenseRequest($productSlug, $licenseKey, $token, $this->post); $siteUrl = $this->sanitizeSiteUrl(isset($this->post['site_url']) ? strval($this->post['site_url']) : ''); $usingToken = !empty($token); $response = array('license' => $this->prepareLicenseForOutput($license, $usingToken)); if (!$usingToken) { $token = $this->wpdb->get_var($this->wpdb->prepare("SELECT token FROM `{$this->tablePrefix}tokens` WHERE site_url = %s AND license_id = %d", $siteUrl, $license['license_id'])); } if (empty($token)) { //The user tried to un-license a site that wasn't licensed in the first place. Still, //the desired end state - site not licensed - has ben achieved, so treat it as a success. $response['notice'] = "The specified site wasn't licensed in the first place."; } else { $this->wpdb->delete($this->tablePrefix . 'tokens', array('token' => $token, 'license_id' => $license['license_id'])); //Reload the license to ensure the site list is correct. $license = $this->loadLicense($license['license_key']); $response['license'] = $this->prepareLicenseForOutput($license, $usingToken); $response = array_merge($response, array('site_token_removed' => $token, 'site_url' => $siteUrl)); } $this->outputResponse($response); }
function allowed_redirect_hosts($allowed_hosts) { if (!empty($_REQUEST['redirect_to'])) { $redirect_url = parse_url($_REQUEST['redirect_to']); if (isset($redirect_url['host'])) { $network_home_url = parse_url(network_home_url()); if ($redirect_url['host'] != $network_home_url['host']) { $pos = strpos($redirect_url['host'], '.'); if ($pos !== false && substr($redirect_url['host'], $pos + 1) === $network_home_url['host']) { $allowed_hosts[] = $redirect_url['host']; } $bid = $this->db->get_var("SELECT blog_id FROM {$this->dmtable} WHERE domain = '{$redirect_url['host']}' ORDER BY id LIMIT 1"); if ($bid) { $allowed_hosts[] = $redirect_url['host']; } } } } else { $domains = (array) $this->db->get_col(sprintf("SELECT domain FROM %s WHERE blog_id = %d ORDER BY id ASC", DOMAINMAP_TABLE_MAP, $this->db->blogid)); $original = $this->db->get_var("SELECT domain FROM {$this->db->blogs} WHERE blog_id = " . intval($this->db->blogid)); $allowed_hosts = array_unique(array_merge($allowed_hosts, $domains, array($original))); } return $allowed_hosts; }
$ticket_cdata = $keyost_prefix . "ticket__cdata"; $staff_table = $keyost_prefix . "staff"; $ost_user = $keyost_prefix . "user"; $ost_useremail = $keyost_prefix . "user_email"; $ost_ticket_attachment = $keyost_prefix . "ticket_attachment"; $ost_ticket_status = $keyost_prefix . "ticket_status"; $ost_file = $keyost_prefix . "file"; $directory = $config['supportpage']; $dirname = strtolower($directory); $category = @$_GET['cat']; $status_opt = @$_GET['status']; $ticket = @$_GET['ticket']; # ============================================================================================== # Changed (id) -> (like) so we search for text in v1.8+ # ============================================================================================== $id_isonline = $ost_wpdb->get_var("SELECT id FROM {$config_table} WHERE {$config_table}.key like ('%isonline%');"); $isactive = $ost_wpdb->get_row("SELECT id,namespace,{$config_table}.key,{$config_table}.value,updated FROM {$config_table} where id = {$id_isonline}"); $isactive = $isactive->value; $id_helptitle = $ost_wpdb->get_var("SELECT id FROM {$config_table} WHERE {$config_table}.key like ('%helpdesk_title%');"); $title_name = $ost_wpdb->get_row("SELECT id,namespace,{$config_table}.key,{$config_table}.value,updated FROM {$config_table} where id ={$id_helptitle}"); $title_name = $title_name->value; $table_name_config = $keyost_prefix . "config"; // STMP Status Start Here By Pratik Maniar $count_smtp_status = $ost_wpdb->get_var("SELECT count(*) FROM {$config_table} WHERE {$config_table}.key like ('%smtp_status%');"); if ($count_smtp_status == 0) { $id = ''; $namespace = "core"; $key = "smtp_status"; $rows_affected = $ost_wpdb->insert($config_table, array('id' => $id, 'namespace' => $namespace, 'key' => $key, 'value' => 'disable', 'updated' => current_time('mysql'))); } $id_smtp_status = $ost_wpdb->get_var("SELECT id FROM {$config_table} WHERE {$config_table}.key like ('%smtp_status%');");
/** * Checks and sees if all the tables are * present and have the correct schema. * * @since 2.0 */ public function testCheckTables() { $quizTable = $this->db->get_var("SHOW TABLES LIKE '" . WPSQT_TABLE_QUIZ_SURVEYS . "'"); $this->assertEquals(WPSQT_TABLE_QUIZ_SURVEYS, $quizTable, "Quiz table not found!"); }
function foodor_getproducts($product_cnt = 1) { //require_once($_SERVER['DOCUMENT_ROOT']."/".get_option('foodor_site_dir')."/wp-config.php"); require_once ABSPATH . "wp-config.php"; /*$test = ABSPATH."wp-config.php"; var_dump($test);*/ //Connect to the olalaco_websajt database //$connection = new wpdb(get_option('foodor_db_username'),get_option('foodor_db_password'), get_option('foodor_db_database'), get_option('foodor_db_server')); $connection = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); //var_dump($connection); $table_name = get_option('foodor_dbtable_prefix') . get_option('foodor_dbtable_name'); if (isset($_GET['id'])) { $id = $_GET['id']; $sqlget = "SELECT * FROM {$table_name} WHERE id = " . $id; if (!($results = $connection->get_results($sqlget))) { die('Ne mogu da izvrsim upit zbog [' . $connection->error . "]"); } //print_r("Results iznosi: $results"); //var_dump($results); $writeget = ""; $writeget .= "<div class='main container-fluid'>"; $writeget .= "<div class='sectionShow'>"; foreach ($results as $rowget) { //print_r("Rowget iznosi: $rowget"); //var_dump($rowget); $writeget .= "<div class='secimg''>"; $writeget .= "<img src='{$rowget->image_url}' alt='Item Photo' style='width:200px;height:200px'>"; $writeget .= "</div>"; $writeget .= "<div class='secol'>"; $writeget .= "<ul class='ulindex''>"; $writeget .= "<li><h1>Naziv artikla: {$rowget->title}</h1></li>"; $writeget .= "<li><h4>Opis: {$rowget->description}</h4></li>"; $writeget .= "<li><h3>Cena: {$rowget->price} din</h3></li>"; $writeget .= "<br />"; $writeget .= "<br />"; $writeget .= "<li><a href='foodorder'>Vrati se na ponudu.</a></li>"; $writeget .= "</ul>"; $writeget .= "</div>"; } $writeget .= "</div>"; $writeget .= "</div>"; return $writeget; } /* If is posted form then create and return table with variable $tablepost */ if (isset($_POST['submit'])) { $item_arr = array(); for ($i = 1; $i < 100; $i++) { $ordered_id = "id" . $i; $price = "price" . $i; $col = "col" . $i; $title = "title" . $i; if (isset($_POST[$ordered_id]) && $_POST[$ordered_id] == $i) { $item_arr[$i][$ordered_id] = $_POST[$ordered_id]; $item_arr[$i][$price] = $_POST[$price]; $item_arr[$i][$col] = $_POST[$col]; $item_arr[$i][$title] = $_POST[$title]; } } //print_r($item_arr); //$lenght = count($item_arr); //echo "Ukupno ima {$lenght} zapisa u porudzbini"; if (isset($ordered_id)) { $n = 0; foreach ($item_arr as $item_arr_key => $one_array) { $i = 0; foreach ($one_array as $key => $value) { //echo "<br />Brojac iznosi {$i} - Key je: {$key} - upisana vrednost {$value}"; $new_array[$n][$i] = $value; $i++; } $n++; } } if (isset($new_array) && !empty($new_array)) { $tablepost = ''; $tablepost .= '<table class="table datagrid">'; $tablepost .= '<tr style="background-color: chocolate">'; $tablepost .= '<th>ID</th>'; $tablepost .= '<th>Artikal</th>'; $tablepost .= '<th>Cena</th>'; $tablepost .= '<th>Kolicina</th>'; $tablepost .= '<th>Vrednost</th>'; $tablepost .= '</tr>'; foreach ($new_array as $new_array_row) { $tablepost .= "<tr>"; if ($new_array_row[2] != 0) { $tablepost .= "<td>"; $tablepost .= $new_array_row[0]; $tablepost .= "</td><td>"; $tablepost .= $new_array_row[3]; $tablepost .= "</td><td>"; $tablepost .= $new_array_row[1]; $tablepost .= "</td><td>"; $tablepost .= $new_array_row[2]; $tablepost .= "</td><td>"; $tablepost .= $valu_one = $new_array_row[1] * $new_array_row[2]; $tablepost .= "</td>"; $tablepost .= "</tr>"; if (isset($valu_one)) { $value_all = $value_all + $valu_one; } } } $tablepost .= "</table>"; } return $tablepost; } /********** Example from tutorial **************/ $retval = ''; for ($i = 0; $i < $product_cnt; $i++) { //Get a random product $product_count = 0; while ($product_count == 0) { $product_id = rand(0, 30); $product_count = $connection->get_var("SELECT COUNT(*) FROM {$table_name} WHERE id={$product_id} AND today_menu=1"); } //Get product image, name and URL $product_image = $connection->get_var("SELECT image_url FROM {$table_name} WHERE id={$product_id}"); $product_name = $connection->get_var("SELECT title FROM {$table_name} WHERE id={$product_id}"); //Build the HTML code $retval .= '<div class="foodor_product">'; $retval .= '<img src="' . $product_image . '" style="width:100px; heigth:100px;" /><br />'; $retval .= '<a href=orders/showItem.php?id=' . $product_id . '>' . $product_name . '</a>'; $retval .= '</div>'; } //return $retval; /*********** End of Example from tutorial **********/ $sql = "SELECT * FROM {$table_name} WHERE menu = 1 ORDER BY id ASC "; //print_r($sql); if (!($results = $connection->get_results($sql))) { die('Ne mogu da izvrsim upit zbog [' . $connection->error . "]"); } //$uri = trim($_SERVER['REQUEST_URI'], '/'); $uri = str_replace('%7E', '~', $_SERVER['REQUEST_URI']); $uri = trim($uri, '/'); $writeout = ""; $writeout .= "<form method='post' action='{$_SERVER['REQUEST_URI']}'>"; $writeout .= "<input type='submit' name='submit' value='Odaberite količine i potvrdite porudžbinu ovde' class='btn btn-default btn-lg btn-block'>"; $writeout .= "<div class='main container-fluid' style='margin-top: 10px'>"; //WHILE ($row = $results->fetch_assoc()){ foreach ($results as $rowobj) { $writeout .= "<div class='secolPhoto' style='border-color: #d2691e;'>"; $writeout .= "<table class='table datagrid' style='width: 30%; float: left;'>"; $writeout .= "<tr style='background-color: chocolate'>"; $writeout .= "<th style='width: 40%'>ID: <a style='color:darkred' href='{$uri}?id={$rowobj->id}'>{$rowobj->id}</a></th>"; $writeout .= "<th style='width: 130px'><input type='text' name='title{$rowobj->id}' value='{$rowobj->title}' style='background-color: #d2691e; width: 130px; border: none;' readonly></th>"; $writeout .= "</tr>"; $writeout .= "<tr>"; $writeout .= "<td style='width: 40%'>{$rowobj->description}</td>"; $writeout .= "<td style='width: 130px'><a href='{$uri}?id={$rowobj->id}' ><img src={$rowobj->image_url} style='width:100px; height:100px;'></a></td>"; $writeout .= "</tr>"; $writeout .= "<tfoot>"; $writeout .= "<td style='width: 40%'><input style='width: 100px' type='money' name='price{$rowobj->id}' value='{$rowobj->price}' readonly></td>"; $writeout .= "<td style='width: 130px' colspan = '2'>"; $writeout .= "<input type='hidden' name='id{$rowobj->id}' value='{$rowobj->id}' style='border: none'>"; $writeout .= "<span style='color:#8b0000'>Količina: <input style='width: 50px' type='number' name='col{$rowobj->id}' min='0' max='10' value='0'></span>"; $writeout .= "</td>"; $writeout .= "</table>"; $writeout .= "</div>"; } $writeout .= "</div>"; $writeout .= "</form>"; return $writeout; }
public function get_var($query = null, $x = 0, $y = 0) { $this->check_current_query = false; return parent::get_var($query); }
/** * Checks whether the table is exists * @param string $table The name of the table * @return bool TRUE if the table is exists, FALSE otherwise */ public function isTableExists($table) { return $this->db->get_var(sprintf('SHOW TABLES LIKE %s', $table)) == $table; }
/** * @see wpdb::get_var() */ function get_var($query = null, $x = 0, $y = 0) { if ($this->ignore_query($query)) { return parent::get_var($query, $x, $y); } $this->init_cache(); $key = md5('get_var(' . $query . ',' . $x . ',' . $y . ')'); $result = null; $cache = $this->get_cache_item($key); if ($cache) { $result = $cache['result']; $this->last_result = $cache['last_result']; $this->num_rows = $cache['num_rows']; } else { $result = parent::get_var($query, $x, $y); $cache = array('result' => $result, 'last_result' => $this->last_result, 'num_rows' => $this->num_rows); $this->set_cache_item($key, $cache); } return $result; }
/** * Return a single field as a value given SQL select statement keys and params list. * * If more than one record is returned it will only fetch the result of the first record. * * @param string[] $commandList * @param mixed[] $params */ function get_Value($commandList, $params) { return $this->db->get_var($this->db->prepare($this->get_SQL($commandList), $params)); }
/** * Check if email exists * * @param $email * * @return mixed */ public function emailExists($email) { return $this->wpdb->get_var($this->wpdb->prepare("SELECT * FROM {$this->table} WHERE email = %s", $email)); }
$ost_email = $keyost_prefix . "email"; $ost_staff = $keyost_prefix . "staff"; $ost_useremail = $keyost_prefix . "user_email"; $ost_ticket_attachment = $keyost_prefix . "ticket_attachment"; $ost_ticket_status = $keyost_prefix . "ticket_status"; $ost_file = $keyost_prefix . "file"; $directory = $config['supportpage']; $dirname = strtolower($directory); $category = @$_GET['cat']; $status_opt = @$_GET['status']; $ticket = @$_GET['ticket']; $parurl = $_SERVER['QUERY_STRING']; $page_id_chk = @$_REQUEST['page_id']; get_currentuserinfo(); $user_email = $current_user->user_email; $id_isonline = $ost_wpdb->get_var("SELECT id FROM {$config_table} WHERE {$config_table}.key like ('%isonline%');"); $isactive = $ost_wpdb->get_row("SELECT id,namespace,{$config_table}.key,{$config_table}.value,updated FROM {$config_table} where id = {$id_isonline}"); $isactive = $isactive->value; //Added By Pratik Maniar on 01-05-2014 Start Here $default_email_id = $ost_wpdb->get_var("SELECT value FROM " . $keyost_prefix . "config WHERE `key` LIKE 'default_email_id'"); $default_email_id_data = $ost_wpdb->get_row("SELECT * FROM " . $keyost_prefix . "email WHERE `email_id` ={$default_email_id}"); //Added By Pratik Maniar on 01-05-2014 End Here $title_name = $default_email_id_data->name; $id_maxopen = $ost_wpdb->get_var("SELECT id FROM {$config_table} WHERE {$config_table}.key like ('%max_open_tickets%');"); $max_open_tickets = $ost_wpdb->get_row("SELECT id,namespace,{$config_table}.key,{$config_table}.value,updated FROM {$config_table} where id = {$id_maxopen}"); $max_open_tickets = $max_open_tickets->value; $os_admin_email = $default_email_id_data->email; $id_hidename = $ost_wpdb->get_var("SELECT id FROM {$config_table} WHERE {$config_table}.key like ('%hide_staff_name%');"); $hidename = $ost_wpdb->get_row("SELECT id,namespace,{$config_table}.key,{$config_table}.value,updated FROM {$config_table} where id = {$id_hidename}"); $hidename = $hidename->value; if ($isactive != 1) {
/** * Set up the amount of found posts and the number of pages (if limit clause was used) * for the current query. * * @since 3.5.0 * @access private * * @param array $q Query variables. * @param string $limits LIMIT clauses of the query. */ private function set_found_posts($q, $limits) { // Bail if posts is an empty array. Continue if posts is an empty string, // null, or false to accommodate caching plugins that fill posts later. if ($q['no_found_rows'] || is_array($this->posts) && !$this->posts) { return; } if (!empty($limits)) { /** * Filters the query to run for retrieving the found posts. * * @since 2.1.0 * * @param string $found_posts The query to run to find the found posts. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $this->found_posts = $this->db->get_var(apply_filters_ref_array('found_posts_query', array('SELECT FOUND_ROWS()', &$this))); } else { $this->found_posts = count($this->posts); } /** * Filters the number of found posts for the query. * * @since 2.1.0 * * @param int $found_posts The number of posts found. * @param WP_Query &$this The WP_Query instance (passed by reference). */ $this->found_posts = apply_filters_ref_array('found_posts', array($this->found_posts, &$this)); if (!empty($limits)) { $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']); } }
/** * Convert language to mlp culture. ie: hr_HR * * @param wpdb $wpdb * @param $language * * @return mixed|string */ public static function convert_to_mlp_lang_obj(wpdb $wpdb, $language) { $query = $wpdb->prepare("SELECT http_name FROM `wp_mlp_languages` WHERE iso_639_1 = " . "%s LIMIT 1", $language); $result = $wpdb->get_var($query); return NULL === $result ? $language : str_replace('-', '_', $result); }