Advertisement
Guest User

Query Meta Data

a guest
Oct 5th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. <?php
  2. // display error
  3. ini_set('display_errors',1);
  4. ini_set('display_startup_errors',1);
  5. error_reporting(-1);
  6. $con = dbconn();
  7. if (!mysqli_connect_errno()) {
  8.    
  9.    echo 'connected';
  10.    
  11.    //Database Connection
  12.    $query_exec = mysqli_query($con, "set names 'utf8'");
  13.    $query_search = "
  14.   SELECT
  15.      p.post_title,
  16.      p.post_date,
  17.      usd_buy.meta_value AS 'USD Buy',
  18.      usd_sell.meta_value AS 'USD Sell',
  19.      thb_buy.meta_value AS 'THB Buy',
  20.      thb_sell.meta_value AS 'THB Sell'
  21.   FROM  pr65ac2015_posts p
  22.   INNER JOIN  pr65ac2015_postmeta AS usd_buy ON usd_buy.post_id = p.ID
  23.   INNER JOIN  pr65ac2015_postmeta AS usd_sell ON usd_sell.post_id = p.ID
  24.   INNER JOIN  pr65ac2015_postmeta AS thb_buy ON thb_buy.post_id = p.ID
  25.   INNER JOIN  pr65ac2015_postmeta AS thb_sell ON thb_buy.post_id = p.ID
  26.   where
  27.      p.post_type = 'exchange' AND
  28.      p.post_status = 'publish' AND
  29.      usd_buy.post_id = 'usd_buy' AND
  30.      usd_sell.post_id = 'usd_sell' AND
  31.      thb_buy.post_id = 'thb_buy' AND
  32.      thb_sell.post_id = 'thb_sell'
  33. ";
  34.    $query_exec = mysqli_query( $con, $query_search );
  35.    if ( $query_exec ) {
  36.       echo '1';
  37.       $rowcount = mysqli_num_rows($query_exec);
  38.       var_dump($rowcount);
  39.       if( $rowcount > 0 ){
  40.          echo '2';
  41.          while ( $row = mysqli_fetch_assoc( $query_exec ) ) {
  42.             $output[] = $row;
  43.          }
  44.          
  45.          echo "json_encode";
  46.          print( json_encode( $output, JSON_UNESCAPED_UNICODE ) ) ;
  47.       } else {
  48.          echo '1';
  49.       }
  50.    }
  51.    mysqli_close( $con );
  52. }
  53. function dbconn() {  
  54.    $strHostName = "localhost"; // host
  55.    $strDbName = "mywebsite"; // database name
  56.    $strUserName = "root"; // database username
  57.    $strPassword = ""; // database password
  58.    return new mysqli($strHostName, $strUserName, $strPassword, $strDbName);
  59. }
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement