Tag Info

Hot answers tagged

4

I think the problem might lie in: $wpdbinfo = $wpdb->get_results("SELECT * FROM bo_mytable WHERE id=3"); $wpdb->get_results() returns an array of objects, yet you are referencing a property on $wpdbinfo (->nameinfo). You'll either want to loop through the $wpdbinfo array, or if you're certain you'll get only a single record (possibly a safe ...


3

As said in Codex, wpdb::get_results(): the function returns the entire query result as an array (bold mine) So, your $wpdbinfo is not an object, but an array, and if you had turn on WP_DEBUG, your code had thrown a warning. When you need one single row form db, use wpdb::get_row() and when you need a single variable (like in your example) use ...


2

Try to replace: AND meta_value LIKE %s with AND meta_value LIKE '%%%s%%' so your SQL will become: AND meta_value LIKE '%The%' instead of: AND meta_value LIKE 'The'


2

I'm looking at wp-db.php and see: 1384 if ( $this->dbh->connect_errno ) { 1385 $this->dbh = null; This is in the class function db_connect(), which is called by the wpdb constructor. In the latest error you describe: Warning: mysql_error() expects parameter 1 to be resource, ...


2

First of all, WordPress provides better ways to query with database. You should not make your query directly with $wpdb unless it's absolutely necessary. You should use WP_Query and get_posts() instead to receive data from WordPress database. If you want to read more about it, read here. @Rarst provided great explanation on better ways to make query in ...


1

The only neat way to get a full permalink is to make use of the get_permalink() function, @see http://codex.wordpress.org/Function_Reference/get_permalink get_permalink($obj->ID);


1

You should try to replace the meta_value = $list->ID part with the placeholder meta_value = %d. Then use the following: $subscriber_count = $wpdb->get_var( $wpdb->prepare( $q, $list->ID ) ); where the input argument $list->ID will be treated as an integer (signed). From the Codex: The query parameter for prepare accepts sprintf()-like ...


1

By default, wordpress get_results return a numerically array of objects, so to use echo to print your data yo should do something like; foreach($myrows as $line){ echo $line->question; }


1

I solved it instead of using return ( $result == true ? 'success' : 'error' ); use echo ( $result == true ? 'success' : 'error' );


1

Just to clarify the get_var() method of $wpdb does work just fine in this context: global $wpdb; $helloworld_id = $wpdb->get_var("SELECT ID FROM wp_posts WHERE post_name = 'hello-world'"); echo $helloworld_id; Actually it is more practical in this context, because a single variable is returned, which is what is actually wanted.


1

Why do your own database queries? Use the WP functions to do it for you. $empid = (int) $_REQUEST['empid']; $name = get_user_meta($empid, 'first_name', true) . ' ' . get_user_meta($empid, 'last_name', true);



Only top voted, non community-wiki answers of a minimum length are eligible