K
K
kally2019-11-30 17:14:21
PHP
kally, 2019-11-30 17:14:21

How to get article id from table? How to extract data from a specific article?

I gave the articles on the article.php article page not the url format article.php?=34
but the following article.php/unique-article-name
through the code
<a href = 'article.php/{$result["title1"]}'>
. As a result, we got unique article names, not faceless numbers. But the articles themselves are not displayed.
It is not possible to get either the id of the article or this unique title title1. In the database, there is only one primer key opposite the article number.
I checked getting the title or article id through the following code
$sql = mysqli_query($link, 'SELECT * FROM `art`');
if (isset($_GET['id'])) {
echo "OK";
} else {
echo "NO";
}

Writes know all the time. page title looks like
site.com/article.php/unique-article-name
I really appreciate everyone's help!
Got this code

if (isset($_GET['id'])) {

  $sql = mysqli_query($link, 'SELECT * FROM `art` WHERE `id` = "' . mysqli_real_escape_string($link, $_GET['id']) . '" LIMIT 1');
  
  while ($result = mysqli_fetch_array($sql)) {
    echo "<h3>Title !!! </h3><p>{$result['text']}</p>";
  }

The whole thing was in one line. It should have been like this, but it was like this Url articles Have a good evening everyone!
mysqli_real_escape_string($link, $_GET['id'])
mysql_real_escape_string($_GET['id'])
<a href = 'article.php?id={$result["id"]}'>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Araik, 2019-11-30
@kally

GET parameters are passed in the address bar, so your check returns NO all the time
I understand it was something like this? Judging by the answers / questions, the simplest solution for you will be something like this:
or like this:
Another option is to search the database for an article not by id, but by title (not the best option).
This is about simple solutions.
Similar question: How to make a CNC in PHP with a DB field?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question