如何从href标签中获取价值

时间:2019-12-25 18:41:18

标签: php html mysql

因此,我有一个名为news.php的网页,其中显示了数据库中的所有网站新闻。 我想创建一个新页面,以按数据库中的新闻ID仅查看单个新闻,例如,该页面显示为showews.php

所以这是我的index.php

import React, { Component } from 'react';
import AComponent from "./image";
const Ctext = (props) => (
<div>
<h5 className="card-title">Image n Text Card</h5>
 <p className="card-text">{props.dataFromParent.textContent}</p>
</div>
);

export default Ctext;
export const props => <AComponent />;

我的body.php包含此内容,可将网址修改为/?p = pagename:

<?php
include('config/webconf.php');
include('includes/head.php');
include('includes/nav.php');
include('includes/body.php');
include('includes/foot.php');
?>

news.php(显示所有新闻)

<?php
if(isset($_GET['p'])) {
  if(file_exists("pages/" . $_GET['p'] . ".php")) {
    include("pages/" . $_GET['p'] . ".php");
  }else{
    include("pages/notfound.php");
  }
}else{
  include("pages/info.php");
}
?>

所以在showdews.php中,我想从$ newsid获取ID,但是我认为由于URL是/?p = shownews?id = 1而无法获取它,因为URL名称函数找不到 shownews ?id = 1 (找不到页面)

所以我试图将/?p = shownews更改为pages / shownews.php?id = $ newsid:

mysqli_select_db($conn, $webdb);
$stmt = $conn->prepare("SELECT id,title, content, author FROM news");
$stmt->execute();
$stmt->bind_result($newsid, $title, $content, $author);
$stmt->store_result();
if($stmt->num_rows > 0) {
  while($stmt->fetch()) {
     echo $title." (<a href='/?p=shownews?id=".$newsid."' target='_blank'>view</a>)";
 }
}

现在我可以通过show_ews.php中的$ _GET函数获得$ news id,但是网站样式像div / background等一样消失了。

我的问题是,我可以在不更改url名称功能的情况下在页面showews.php中获取新闻ID吗?

0 个答案:

没有答案