How to get a value-only flat array from $wpdb->get_results when selecting a single column, without foreach()?

My query is:

$  var = $  wpdb->get_results("SELECT field FROM {$  wpdb->prefix}table", ARRAY_A); var_dump($  var); 

it returns someting like array(2) { [0]=> array(1) { ["field"]=> string(5) "test1" } [1]=> array(1) { ["field"]=> string(t) "test2" }. I.e. each item is a row with a single name-value pair.

What I want is array(2) { [0]=> string(5) "test1" [1]=> string(5) "test2" }

Currently I achieve it like this:

$  var = $  wpdb->get_results("SELECT field FROM {$  wpdb->prefix}table"); foreach($  var as $  v_key => $  v_val) $  var[$  v_key] = $  v_val['field']; var_dump($  var); 

Is there a shorter way to do this?

3D plot from an array

I have an array on the following form:

Array[1, {20, 20, 3}]; 

and i want to visualise the data in 3D plot, i tried many times but usually Mathematica reply that there is an error.

here is a part of the code enter image description here

part of the data

{{{0, 0, {0.20667}}, {0, 1, {0.584291}}, {0, 2, {0.948858}}, {0,3, {0.922532}}}, {{1, 0, {0.20667}}, {1, 1, {0.188105}}, {1,2, {0.000314782}}, {1, 3, {0.163525}}}, {{2, 0, {0.20667}}, {2,1, {0.948938}}, {2, 2, {0.0784778}}, {2, 3, {0.00361825}}}, {{3,0, {0.20667}}, {3, 1, {0.772576}}, {3, 2, {0.466603}}, {3,3, {0.00774734}}}} 

How to make a discrete circle in a 2d array?

I’m trying to make a filled-in circle in a 2d matrix. Any value less than r is 1, and any value outside of r is zero. I’m looking for something that looks more circular as the array size grows. The circle should be centered in the array

I’m starting out with an array full of zeros, and trying to use a loop to assign values of 1, but I’m not getting anything that looks remotely like a circle.

Here’s what I’ve tried:

width = 100 height = 100 radius = 20 halfwidth = width/2 halfheight=height/2  array = ConstantArray[0, {height, width}] For[i=0, i<width, i++; For j=0, j<height, j++; If[i*i +j*j < radius*radius, array[[i + halfheight -  radius, j+halfwidth-radius]]=1]]]] 

The last line SHOULD iterate over the entire 2d array and then checks if that index falls within the circle. If True, it assigns a value of 1, else it does nothing. Obviously, it’s not doing that. This is what it produces:

Not very circular circle

It looks like it might be creating a single quadrant of the circle, but if so its in the wrong place.

So, how do I center this, and make a complete circle?

Thanks!

WordPress primitive query returns = array

i am trying to primitive query form this wp_query:

$  query_v = array(     'post_type' => array('pro'),     'posts_per_page'    => -1,     'orderby' => $  count_visit,     'order' => 'ASC',     'tax_query' => array(         array(             'taxonomy' => 'servizi_pro',             'field' => 'slug',             'terms' => $  art_p,             'parent' => 0         )     ) ); 

the problem with this wp_query is that it does not sort me by the number of post views counter that I downloaded as an additional plugin, and I am trying to implement in a primita wordpress query, the wp_query with the addition of the instructions to display the type of custom posts based on the number of views:

<?php global $  wpdb; $  cpt = "pro";  $  q = $  wpdb->get_results(     $  wpdb->prepare(" SELECT * FROM {$  wpdb->prefix}term_relationships  LEFT JOIN {$  wpdb->prefix}terms ON {$  wpdb->prefix}term_relationships.term_taxonomy_id = {$  wpdb->prefix}terms.term_id  LEFT JOIN term_taxonomy ON {$  wpdb->prefix}term_relationships.term_taxonomy_id = {$  wpdb->prefix}term_taxonomy.term_id  LEFT JOIN {$  wpdb->prefix}posts  ON {$  wpdb->prefix}term_relationships.object_id = {$  wpdb->prefix}posts.ID  LEFT JOIN post_views ON {$  wpdb->prefix}term_relationships.object_id = {$  wpdb->prefix}post_views.id  WHERE  {$  wpdb->prefix}post_views.type = '4'    AND {$  wpdb->prefix}posts.post_type = '$  cpt'  AND  {$  wpdb->prefix}terms.name = '$  art_p'         ") ); ?>  <?php print_r($  q);?> <?php foreach ($  q as $  r){ ?>     <?php echo "{$  r->post_title}"; ?> <?php } ?> 

but it always returns to me array (), where am I wrong?

How to prevent SQL Injection via the array parameter? (CVE-2017-14069)

Hello, this page suggest that the sql_query

$  r = sql_query("SELECT modcomment FROM users WHERE id IN (" . implode(", ", $  _POST[usernw]) . ")")or sqlerr(__FILE__, __LINE__);
Code (SQL):

is vulnerable to a SQL injection "via the usernw array parameter to nowarn.php."

and the exploit is suggested:

POST nowarned=nowarned&usernw[]=(select*from(select sleep(10))x)
Code (markup):

Please how that sql_query should…

How to prevent SQL Injection via the array parameter? (CVE-2017-14069)

How can I properly loop through an array gotten from my wordpress database and display it to my site

I am trying to display some posts information from my database on my live site. I have done the query correctly because I can view the items on the live site. But I need to take three items to display. The post title, the post content which houses the images, and the post id which links to the posts. I seem to have written it correctly but it does not do anything.

This is the code

<?php      global $  wpdb;                    $  results = $  wpdb->get_results( "SELECT * FROM $  wpdb->posts WHERE `post_type`='post' AND `post_status` = 'publish' LIMIT    20" );    foreach ($  results) {       echo "<div class="card">             <div class="img">              <img src="{post_content}" alt="">             </div>             <div class="info">                <h5>{post_title}</h5>             </div>           </div>";   }    //echo "<pre>";print_r($  results);echo"</pre>";                      ?>  

I am quite new to wordpress and PHP in general.

Time complexity of pairs in array double loop

I know, that the following is: O(n^2),

int count = 0; for(int i = 0; i<array.length(); i++) {    for(int j = i+1; j<array.length(); j++) {        if(array[i] == array[j]) {            count = count + 1;        }    } } 

But, should something like count = count + 1; be taken into account? For predicting or making up a complex time equation, or using sum notation,

n + n-1 + n-2 + n-3 + (…) + 1 

How to draw the heap for an array in Java?

I have an assignment to draw the heap after an ArrayList and a LinkedList is created.

public static void main(String[] args) {      List list = new ArrayList();      list.add(0);      list.add(1);      list.add(1);      list.add(2); } 

and

public static void main(String[] args) {      List list = new LinkedList();     list.add(0);      list.add(1);      list.add(1);      list.add(2); } 

So far I have a tree set up for [0, 1, 1, 2] so that it just goes down like a tree from 0, 1 and 1, then 2. But I don’t know if that’s correct and if it’d be different for the ArrayList and LinkedList.

How could a key could be inserted in a heap without increasing the size of an array?

MAX-HEAP-INSERT(A, key)     A.heap-size = A.heap-size + 1     A[A.heap-size] = -infinity     HEAP-INCREASE-KEY(A,A.heap-size,key) 

How could a key could be inserted in a heap without increasing the size of an array? With this code from Introduction To Algorithms, you can’t just randomly increase the heap size upon wish. Did I miss something? All all online lectures I have seen do no talk about this issue. Neither does the book touch this issue. Or is it that the lowest key in an array would be dropped automatically?

Selecting n elements from array in sublinear time using indices?

Are GPUs or CPUs capable of selecting n elements from an array in sublinear time using indices? If so, what would be some good alternatives to achieve this?

Lets say I have an array A = {1, 5, 6, 3, 6, 2} and indices I = {2, 5, 2, 4, 1, 0}. The resulting array should be: B = {6, 2, 6, 6, 5, 1}. The time complexity for this should be sublinear with respect to the length of I.