Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/topic.php on line 737
Форумы портала PHP.SU :: Выборка записей из бд

 PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи


 Страниц (1): [1]   

> Описание: Ребят, помогите с выборкой пожалуйста
Pavlentiy
Отправлено: 12 Марта, 2014 - 22:42:37
Post Id


Новичок


Покинул форум
Сообщений всего: 14
Дата рег-ции: Июль 2013  


Помог: 0 раз(а)




Есть 2 файла. Главная страница index.php и classPosts.php в котором реализованы методы добавление/выборки постов.
index.php

classPosts.php
PHP:
скопировать код в буфер обмена
  1. <?PHP require "db.php" ?>
  2. <?PHP  
  3.         class Posts extends db {
  4.                 public $stmt ;
  5.                 public $error_records = array() ;
  6.                 public $data = array() ;
  7.  
  8.                 public function add_query_Topic() {
  9.                         $this->mysqli->query("INSERT INTO `topic` (author, content) VALUES('".$_POST['title']."', '".$_POST['topic']."')") ;
  10.                         echo "INSERT INTO `topic` VALUES('".$_POST['title']."', '".$_POST['topic']."')" ;
  11.                 }
  12.  
  13.                 public function setPosts() {
  14.                         if (strlen($_POST['title']) >=10 and strlen($_POST['topic']) >= 15) {
  15.                                 $this->post = htmlspecialchars($_POST['posts'] and $_POST['title']) ;
  16.                                 $this->post = html_entity_decode($this->post) ;
  17.                                 $this->post = strip_tags($this->post) ;
  18.                                 $this->post = trim($this->post) ;  
  19.                          }  else {
  20.                                 $this->error_records['title']=$this->error_records['posts'] = "Заголовок должен быть не менее 10 символов, а содержание статьи не менее 100 символов." ;
  21.                                 }
  22.                                 return count($this->error_records) == 0 ;
  23.                         }
  24.                        
  25.  
  26.                  public function getPosts() {
  27.                                 $this->stmt = $this->mysqli->query("SELECT * FROM `topic` WHERE author and content") ;
  28.                                 echo "SELECT * FROM `topic` WHERE author and content";
  29.                                 $result = $this->stmt ;
  30.                                         while ($row = $result->fetch_assoc()) {
  31.                                                 $this->$data= $row ;
  32.                                         }
  33.                                         return $this->data ;                             
  34.                         }
  35.         }
  36.  
  37.                 $posts = new Posts() ;
  38.  ?>
  39.  


PHP:
скопировать код в буфер обмена
  1. <?PHP session_start() ?>
  2. <?PHP require "classPosts.php" ?>
  3.  
  4. <!DOCTYPE html>
  5. <html>
  6.         <head>
  7.                 <meta charset="UTF-8" />
  8.                 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" charset="UTF-8">
  9.                 <meta name="viewport" content="width=device-width, initial-scale=1.0">
  10.                 <title>Блог</title>
  11.                 <meta name="author" content="Codrops" />
  12.         <link href="css/bootstrap.min.css" rel="stylesheet">
  13.                 <link rel="shortcut icon" href="../favicon.ico">
  14.  
  15.                 <link rel="stylesheet" type="text/css" href="css/component.css" />
  16.                 <link rel="stylesheet" type="text/css" href="css/main.css" />
  17.                  <script src="js/bootstrap.min.js"></script>
  18.                 <script src="js/modernizr.custom.js"></script>
  19.                  <script src="js/jquery-ui-1.10.4.custom.js"></script>
  20.                 <script scr="js/jquery-2.1.0.min.js"></script>
  21.         </head>
  22.         <body>
  23.  
  24. <div id="menu-style" >
  25.         <nav class="cbp-spmenu cbp-spmenu-vertical cbp-spmenu-left" id="cbp-spmenu-s1">
  26.                         <h3>
  27.                         <label for="login">Логин</label>
  28.                         <input name="login" type="text" />
  29.                         <label for="password">Пароль</label>
  30.                         <input name="password" type="password" />
  31.                         <form action="register.php">
  32.                         <button type="submit" class="btn">Регистрация</button></form> <button class="btn">Войти</button>
  33.                         </h3>
  34.                         <a href="index.php">Главная страница</a>
  35.                         <a href="#">Настройки</a>
  36.                 </nav>
  37.  
  38. </div>
  39.  
  40.  
  41. <div id="mainstyle">
  42.        
  43.         <div id="header-style">
  44.                 <input id="showLeft" type = "image" src = "img/menu.png" name = "open" value = "open" alt="Меню" />
  45.                 <form action="new-topic.php">
  46.                 <input id="b-newtopic" type = "image" src = "img/new-topic.png" alt="Новая статья" /></form>
  47.                                                        
  48.  
  49. </div> <!--header-style -->
  50.                                                                
  51.                                                        
  52.         <div id="content-block">
  53. <?PHP  if (isset($posts) && $posts->setPosts()) {
  54.                         $posts->add_query_Topic() ;
  55.                         $post = $posts->getPosts() ;
  56.                         print_r($post) ;
  57.  
  58.                 }              
  59. ?>
  60.         <?=$data['title']?>
  61.         <?=$data['topic']?>
  62.         <span class="tooltip" data-title="Добавить статью">123457</span>
  63.  
  64.         <div id="lower-info"></div>
  65.         </div>
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.                 <script src="js/classie.js"></script>
  73. <script>
  74.                         var menuLeft = document.getElementById( 'cbp-spmenu-s1' ),
  75.                                 menuRight = document.getElementById( 'cbp-spmenu-s2' ),
  76.                                 menuTop = document.getElementById( 'cbp-spmenu-s3' ),
  77.                                 menuBottom = document.getElementById( 'cbp-spmenu-s4' ),
  78.                                 showLeft = document.getElementById( 'showLeft' ),
  79.                                 showRight = document.getElementById( 'showRight' ),
  80.                                 showTop = document.getElementById( 'showTop' ),
  81.                                 showBottom = document.getElementById( 'showBottom' ),
  82.                                 showLeftPush = document.getElementById( 'showLeftPush' ),
  83.                                 showRightPush = document.getElementById( 'showRightPush' ),
  84.                                 body = document.body;
  85.  
  86.                         showLeft.onclick = function() {
  87.                                 classie.toggle( this, 'active' );
  88.                                 classie.toggle( menuLeft, 'cbp-spmenu-open' );
  89.                                 disableOther( 'showLeft' );
  90.                         };
  91.                         showRight.onclick = function() {
  92.                                 classie.toggle( this, 'active' );
  93.                                 classie.toggle( menuRight, 'cbp-spmenu-open' );
  94.                                 disableOther( 'showRight' );
  95.                         };
  96.                         showTop.onclick = function() {
  97.                                 classie.toggle( this, 'active' );
  98.                                 classie.toggle( menuTop, 'cbp-spmenu-open' );
  99.                                 disableOther( 'showTop' );
  100.                         };
  101.                         showBottom.onclick = function() {
  102.                                 classie.toggle( this, 'active' );
  103.                                 classie.toggle( menuBottom, 'cbp-spmenu-open' );
  104.                                 disableOther( 'showBottom' );
  105.                         };
  106.                         showLeftPush.onclick = function() {
  107.                                 classie.toggle( this, 'active' );
  108.                                 classie.toggle( body, 'cbp-spmenu-push-toright' );
  109.                                 classie.toggle( menuLeft, 'cbp-spmenu-open' );
  110.                                 disableOther( 'showLeftPush' );
  111.                         };
  112.                         showRightPush.onclick = function() {
  113.                                 classie.toggle( this, 'active' );
  114.                                 classie.toggle( body, 'cbp-spmenu-push-toleft' );
  115.                                 classie.toggle( menuRight, 'cbp-spmenu-open' );
  116.                                 disableOther( 'showRightPush' );
  117.                         };
  118.  
  119.                         function disableOther( button ) {
  120.                                 if( button !== 'showLeft' ) {
  121.                                         classie.toggle( showLeft, 'disabled' );
  122.                                 }
  123.                                 if( button !== 'showRight' ) {
  124.                                         classie.toggle( showRight, 'disabled' );
  125.                                 }
  126.                                 if( button !== 'showTop' ) {
  127.                                         classie.toggle( showTop, 'disabled' );
  128.                                 }
  129.                                 if( button !== 'showBottom' ) {
  130.                                         classie.toggle( showBottom, 'disabled' );
  131.                                 }
  132.                                 if( button !== 'showLeftPush' ) {
  133.                                         classie.toggle( showLeftPush, 'disabled' );
  134.                                 }
  135.                                 if( button !== 'showRightPush' ) {
  136.                                         classie.toggle( showRightPush, 'disabled' );
  137.                                 }
  138.                         }
  139.                 </script>
  140.         </body>
  141. </html>


Дело в том, что запись в бд добавляется, а выборка из бд не происходит. Метод getPosts не срабатывает. Подскажите пожалуйста, в чем проблема и как её решить?

(Отредактировано автором: 13 Марта, 2014 - 08:11:43)

 
 Top
Pavlentiy
Отправлено: 13 Марта, 2014 - 07:05:29
Post Id


Новичок


Покинул форум
Сообщений всего: 14
Дата рег-ции: Июль 2013  


Помог: 0 раз(а)




Кто нибудь подскажет?
(Добавление)
Все, исправил. Тему можно закрыть)
 
 Top
Страниц (1): [1]
Сейчас эту тему просматривают: 0 (гостей: 0, зарегистрированных: 0)
« Вопросы новичков »


Все гости форума могут просматривать этот раздел.
Только зарегистрированные пользователи могут создавать новые темы в этом разделе.
Только зарегистрированные пользователи могут отвечать на сообщения в этом разделе.
 



Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB