致命错误:在第36行的C:\ xampp \ htdocs \personal\post.php中的非对象上调用成员函数fetch_array() [英] Fatal error: call to a member function fetch_array() on a non-object in C:\xampp\htdocs\personal\post.php on line 36

查看:113
本文介绍了致命错误:在第36行的C:\ xampp \ htdocs \personal\post.php中的非对象上调用成员函数fetch_array()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的PHP学习者,我希望通过id.But调用数组顺序显示在页面顶部

I am new PHP learner and I wanted to call arrays order by id.But on the top of the page it shows

Notice: Undefined index: id in C:\xampp\htdocs\personal\post.php on line 9





我的尝试:





What I have tried:

<?php

include "libs/db.php";
include "libs/config.php";
include "function.php";
$db = new database();
$id = $_GET['id'];
$query = "SELECT * from posts WHERE id = '$id'";
$posts = $db->select($query);

?>
<!DOCTYPE html>
<html>
<title>W3.CSS Template</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
    <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<style>
body,h1,h2,h3,h4,h5 {font-family: "Raleway", sans-serif}
</style>
<body class="w3-light-grey">

<!-- w3-content defines a container for fixed size centered content, 
and is wrapped around the whole page content, except for the footer in this example -->
<div class="w3-content" style="max-width:1400px">

<!-- Header -->
<header class="w3-container w3-center w3-padding-32"> 
  <a href="index.php?container.php"><h1>MY BLOG</h1></a>
  <p>Welcome to the blog of <span class="w3-tag">Programmer</span></p>
</header>
 <?php $row = $posts->fetch_array()  ;?>
<!-- Grid -->
<div class="w3-row">

<!-- Blog entries -->
   
<div class="w3-col l8 s12">
  <!-- Blog entry -->

  <div class="w3-card-4 w3-margin w3-white">
    <img src="images/<?php echo $row['image'];?>" alt="Nature" style="width:100%">
    <div class="w3-container">
    	
      <h3><?php echo $row['title'];?></h3>
      <h5>Posted by Sulaymonov on <span class="w3-opacity"><?php echo formatDate($row['date']);?></span></h5>
    </div>
    <div class="w3-container">
      <p><?php echo $row ['content'];?></p>
      <div class="w3-row">
        <div class="w3-col m8 s12">
         
        </div>

        <div class="w3-col m4 w3-hide-small">
          <p><span class="w3-padding-large w3-right">Comments   <span class="w3-tag">0</span></span></p>
        </div>
      </div>
    </div>
  </div>
  <hr>

<!-- END BLOG ENTRIES -->
</div>

推荐答案

db = new database();
db = new database();


id =


_GET ['id'];
_GET['id'];


这篇关于致命错误:在第36行的C:\ xampp \ htdocs \personal\post.php中的非对象上调用成员函数fetch_array()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆