Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 MySql Query for Wordpress, How to write the code

views
     
TStransfield
post May 24 2015, 11:49 PM, updated 9y ago

Rich Old Man
*****
Senior Member
946 posts

Joined: Apr 2006
From: Kuala Lumpur


Hi,
I am editing a Wordpress plugin. I basically want to query the Wordpress database & do something with the results. I've figured out the 1st part which is:
CODE
<?php
global $wpdb;
$my_table = $wpdb->prefix."users";
$my_query = "Select user_login from $my_table where user_login LIKE '%z%' ";
$my_results = $wpdb->get_results($my_query);
?>

I don't know how to get the second part done. I want to put the search results into the foreach loop.
CODE
<?php
foreach($my_results as $user_data)
{
/*Lets assume that I have 100 records from the search results. How do I put all the 100 records into the code below? This means that the search results needs to go into michael_jackson, joe_bugner, etc*/
if($user_data -> user_login === 'michael_jackson' || $user_data -> user_login === 'joe_bugner' )
// do something
}
?>


This post has been edited by transfield: May 24 2015, 11:51 PM

 

Change to:
| Lo-Fi Version
0.0118sec    0.58    5 queries    GZIP Disabled
Time is now: 28th March 2024 - 05:08 PM