поиск на сайте с выводом результатов из бд в виде таблицы

Рейтинг: 0Ответов: 0Опубликовано: 20.02.2023

Такая задача : есть на странице поиска 4 инпута - название, автор, год, под редакцией(title, author, year, compedit). Вводя нужные поля или вообще все -> вывести похожие результаты с таблицы(infprintedit) на страницу в виде таблицы. Но вот еще в чём дело , на сайте две роли и они могут искать( обращаются к странице поиска) у каждого своя , мне значит нужно два php скрипта сделать и чтобы у каждой роли свой переход был?

findpolz.php

<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="style/style.css">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Научно-справочная библиотека</title>
</head>

<body>
    <h1>Пользователь: ____</h1>
    <form method="POST" action="/vendor/search.php">
    <div style="display:flex; flex-direction: row; justify-content: center; align-items: center">
        
            <div class="info">
                <label>Название:</label>
                <input type="text" />
            </div>
            <br>
            <div class="info">
                <label>Автор:</label>
                <input type="text" />
            </div>
            <br>
            <div class="info">
                <label>Год:</label>
                <input type="text" />
            </div>
            <br>
            <br>
            <div class="info">
                <label>Под редакцией:</label>
                <input type="text" />
            </div>
            <br>
            <br>
            <div class="info">
                <form action="findpolz.php">
                    <input type="submit" name="SubmitForm" value="Поиск" />
                </form>
            </div>
        </form>
        <br>
        <br>
        <div class="info">
            <form action="index.html">
                <input type="submit" name="SubmitForm" value="Выход" />
            </form>
        </div>
    </div>
</body>

</html>

search.php

<?php
session_start();
require_once 'connect.php';
$title = trim($title);
$author = trim($author);
$year = trim($year);
$compedit = trim($compedit);
$title = strip_tags($title);
$author = strip_tags($author);
$year = strip_tags($year);
$compedit = strip_tags($compedit);
$q = mysqli_query($connect, "SELECT title,author,year,compedit FROM `infprintedit` WHERE title LIKE '%$title%' or author LIKE '%$author%' or year LIKE '%$year%' or compedit LIKE '%$compedit%' ");
$itog = mysqli_fetch_assoc($q);
while ($itog = mysqli_fetch_assoc($q)) {
    printf("%s (%s)\n",$r["title"], $r["author"],$r["year"], $r["compedit"]);
}
mysqli_free_result($q);
mysqli_close($connect);
?>

Ответы

Ответов пока нет.