title: Retrieve Data from Database using Shortcode
body: <p>I am trying to retrieve data from a wordpress table using a shortcode function I found. It works and retrieves the data for all the columns. When I try to specify the columns I want it still give me everything. Ultimately what I am trying to do is retrieve the data for the columns I want and style that data using css (not in a table format). I am new to php so I was wondering if anyone could let me know if this is even possible using shortcodes. If it is possible any help would be appreciated. Thank you in advance, Randy</p>
  
  <p>Here is the code I am using:</p>
  
  <pre><code>if ( !defined( 'WP_FD_ABSPATH' ) )
  
  define( 'WP_FD_ABSPATH', plugin_dir_path( __FILE__ ) );
  
  function wp_first_shortcode($atts){
  global $wpdb;
  $a = shortcode_atts( array(
  'table_name' =&gt; ",
  'columns' =&gt; ",
  ), $atts );
  $showcolumns=array();
  if($a['columns']!=""){
  $column=$a['columns'];
  $showcolumns=explode(',',$a['columns']);
  }
  else{
  $column='*';
  $get_columns=$wpdb-&gt;get_results("describe ".$a['table_name']."");
  foreach($get_columns as $fields) $showcolumns[]=$fields-&gt;Field;
  }
  
  $columncount=count( $showcolumns);
  
  $result_query=$wpdb-&gt;get_results( "select $column from ".$a['table_name']."");
  echo '&lt;table&gt;&lt;tr&gt;';
  for($i=0;$i&lt;$columncount;$i++) echo '&lt;th&gt;'.$showcolumns[$i].'&lt;/th&gt;';
  echo '&lt;/tr&gt;';
  foreach($result_query as $result_row){
  echo '&lt;tr&gt;';
  for($i=0;$i&lt;$columncount;$i++) echo '&lt;td&gt;'.$result_row-&gt;$showcolumns[$i].'&lt;/td&gt;';
  echo '&lt;/tr&gt;';
  }
  echo '&lt;/table&gt;';
  }
  add_shortcode('fetchdata', 'wp_first_shortcode');
  function table_value_function() {
  query_value(array('orderby' =&gt; 'date', 'order' =&gt; 'DESC' , 'showvalues' =&gt; ""));
  wp_reset_query();
  return $return_string;
  }
  ?&gt;
  </code></pre>
  
  <p>Here is the shortcode I am using:</p>
  
  <pre><code>[fetchdata table_name='my_wp_table' columns ='Display_Name' 'First_Name' 'Last_Name' 'Address_1' 'Address_2' 'City' 'State' 'Phone']
  </code></pre>