wpdb

Wordpress $wpdb->get_results and num_rows

南楼画角 提交于 2020-03-18 09:10:45
问题 I'm using the following code: $wpdb->get_results(" SELECT * FROM " . $wpdb->prefix . "product_order WHERE rel = '" . $post["id"] . "' AND `range` = '" . $range . "' AND category = '" . $range . "' "); echo $wpdb->num_rows; num_rows returns 1 even though there is no rows in the database? Any ideas? The variables I am putting in look fine. so it should be querying correctly. 回答1: global $wpdb; $wpdb->get_results(" SELECT * FROM " . $wpdb->prefix . "product_order WHERE rel = '" . $post["id"] . "

Wordpress $wpdb->get_results and num_rows

落花浮王杯 提交于 2020-03-18 09:10:41
问题 I'm using the following code: $wpdb->get_results(" SELECT * FROM " . $wpdb->prefix . "product_order WHERE rel = '" . $post["id"] . "' AND `range` = '" . $range . "' AND category = '" . $range . "' "); echo $wpdb->num_rows; num_rows returns 1 even though there is no rows in the database? Any ideas? The variables I am putting in look fine. so it should be querying correctly. 回答1: global $wpdb; $wpdb->get_results(" SELECT * FROM " . $wpdb->prefix . "product_order WHERE rel = '" . $post["id"] . "

Converting mysql_query to $wpdb->get_results

寵の児 提交于 2020-01-11 13:20:35
问题 Afetr updating php on the server i have some problems with mysql_query. There are 2 functions in your code that have been deprecated in the current version of PHP : mysql_fetch_array() mysql_query() global $table_prefix, $wpdb; // caching database query per comment $ck_cache = array('ck_ips'=>"", 'ck_comment_id'=>0, 'ck_rating_up'=>0, 'ck_rating_down'=>0); $table_name = $table_prefix . "comment_rating"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { temckrating_install(

$wpdb->get_results($query); Returns NULL with variable $query - Same query works hardcoded

筅森魡賤 提交于 2020-01-06 11:48:55
问题 I've been trying to debug this script for a month. The rest of the program is already built and this one thing just will not work. The issue is the $query variable, it returns null unless I hard code - which isn't possible with a search form. I've tried adding '\n', I've tried just putting in the returns, I've changed the " to ' for the beginning. I've tested the rest of the code outside of this block and it all works. I've run tests on this block as you can see from commented out echo

Convert wpdb sql array into php array

走远了吗. 提交于 2020-01-06 08:22:12
问题 With an sql query I'm grabbing the meta_value of a specific row from my wpdb. In sql it's an array, but it outputs in php as a string, like this: a:1:{i:0;a:2:{i:0;s:10:”02/17/2014″;i:1;s:10:”Thom Stark”;}} How can I convert this into a php array, so I can access the values from array 2's indices? My query looks like this: $tabledata = $wpdb->get_row("SELECT meta_value FROM ".$prefix."frm_item_metas WHERE field_id='$fid' AND item_id='$eid'"); $data = $tabledata->meta_value; echo $data;

$wpdb->insert produces “ Duplicate entry '0-0' for Key '1' ”

自闭症网瘾萝莉.ら 提交于 2019-12-25 08:18:37
问题 I'm writing a plugin and trying to insert a new row into the wp_term_relationships table inside of a foreach loop. I know the variables have values because of a var_dump, but for some reason, I'm getting an error consistently. This shows up about 600 times on the show_errors() function: WordPress database error: [Duplicate entry '0-0' for key 1] INSERT INTO wp_term_relationships ( object_id , term_taxonomy_id , term_order ) VALUES ('','','') My Code: foreach ($cb_t2c_cat_check as $values) {

First wpdb insert to mySql new table isn't working

亡梦爱人 提交于 2019-12-25 06:35:47
问题 I created a new mySql table and I need the first field to be an index and a key. I'm not sure I got the terminology right but I simply need that field to automatically increment by 1 with each insert. So I defined that field as an index and gave it the auto_increment attribute. Now I try to insert the first row like this: $wpdb->insert('wp_branches', array(user_id=>$user_id, branchName=>$bname)); The index/key field branchId is missing from this query because I'm counting on the db to

First wpdb insert to mySql new table isn't working

守給你的承諾、 提交于 2019-12-25 06:35:05
问题 I created a new mySql table and I need the first field to be an index and a key. I'm not sure I got the terminology right but I simply need that field to automatically increment by 1 with each insert. So I defined that field as an index and gave it the auto_increment attribute. Now I try to insert the first row like this: $wpdb->insert('wp_branches', array(user_id=>$user_id, branchName=>$bname)); The index/key field branchId is missing from this query because I'm counting on the db to

Wordpress global $wpdb function issue

感情迁移 提交于 2019-12-24 07:25:53
问题 I am working on a plugin, in plugin i want to add data in new table. I create a file "lsp_manage_foo.php" in this file i create <form action="<?php echo plugin_dir_url(__FILE__) ?>lsp_foo/lsp_manage_process.php" method="post" name="lsp_add_foo"> <table width="100%" border="0" cellspacing="4" cellpadding="0"> <tr> <td width="25%"> <label> foo Name </label> </td> <td width="58%"> <input type="text" name="lsp_add_foo" id="lsp_add_foo" value=""> </td> <td width="10%" align="right"> <input type=

Is there any way to use wpdb prepare statements for array implode(' OR ', $myArray)?

穿精又带淫゛_ 提交于 2019-12-24 04:01:33
问题 I'm trying to properly prepare my data for $wpdb $region = $wpdb->get_results( $wpdb->prepare( " SELECT tr.*, count(*) AS jobs_count FROM {$wpdb->terms} tr INNER JOIN {$wpdb->term_taxonomy} tm ON ( tm.term_id = tr.term_id ) INNER JOIN {$wpdb->term_relationships} tmr ON ( tmr.term_taxonomy_id = tm.term_taxonomy_id ) INNER JOIN {$wpdb->posts} p ON ( p.ID = tmr.object_id ) WHERE (tm.parent = '%d' AND tm.taxonomy = '%s' AND p.post_type = '%s' ) GROUP BY name HAVING COUNT(name) > '%d' ", 0,