Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.95 KB | None | 0 0
  1. <?php
  2.  
  3. ######################## LOGIN DATA ################################################
  4. $username   = "egabocom_blog2";
  5. $password   = "#cpa_3x$";
  6. $database   = "egabocom_wrdp1";
  7. $host       = "localhost";
  8.  
  9. ############################# CONSTANT #############################################
  10.  
  11.  
  12. ######################### LOGIN ACTION #############################################     
  13.     $connect = mysql_connect($host, $username, $password);
  14.         mysql_query('SET NAMES utf8');
  15.     @mysql_select_db($database) or die("Unable to select database");  //generate error message
  16.         mysql_query('SET NAMES utf8');
  17.     echo mysql_error(); //show error message
  18.  
  19. ############################### SELECT DB ###########################################
  20.     if (!mysql_select_db("egabocom_wrdp1")) {
  21.     echo "Unable to select db: " . mysql_error();
  22.     exit;
  23.     }
  24.    
  25. ############################### SELECT QUERY ########################################  
  26.     $sql = "
  27.     SELECT wp_posts.post_title
  28.     FROM wp_posts, wp_term_relationships, wp_terms
  29.     WHERE wp_posts.ID = wp_term_relationships.object_id
  30.     and wp_term_relationships.term_taxonomy_id = wp_terms.term_id
  31.     and wp_terms.name like 'ТЕХНОЛОГИИ'
  32.     and wp_posts.post_status = 'publish'  
  33.  and wp_posts.post_type = 'post'
  34.  ORDER BY wp_posts.ID DESC
  35.  LIMIT 6
  36.  
  37.     ";
  38.    
  39. ############################### GET QUERY ##########################################
  40.     $result = mysql_query($sql);  // get
  41.        
  42.     if (!$result) {                                     // error check
  43.     echo "Could not successfully run query ($sql) from DB: " . mysql_error();
  44.     exit;
  45. }
  46.     if (mysql_num_rows($result) == 0) {                 // error check
  47.     echo "No rows found";
  48.     exit;
  49. }
  50.  
  51. ##################################### RESULT FETCH ################################
  52. while ($row = mysql_fetch_assoc($result)) {
  53.  
  54. ######################### ECHO ROWS - HTML ########################################
  55.    // TITLE;
  56.     echo $row['wp_posts.post_title'];
  57.    
  58.  
  59.  
  60.  
  61.  
  62. }
  63. mysql_free_result($result);
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement