基于第一个字母显示“名字”数据

1cklez4t  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(404)

我正在尝试建立一个登录表,允许用户选择他们名字的第一个字母,然后,它将从数据库中获取所有用户,并将其输出到一个可选择的列表中,该列表允许用户选择他们的姓名,然后将他们“登录”的时间戳输入到数据库中,时间戳为单击他们的姓名时的时间戳。
现在我一直在寻找让php进入表的最佳方法,查找所有以所选字母开头的“名字”,并输出名字和姓氏。
示例:我选择“p”,因为我的名字是“pietro aretino”,然后它会给出每个成员的输出,这些成员的名字以“p”开头,还包括他们的姓氏。我在列表“pietro aretino”中找到了我的名字,我选择了它,然后它会将我的登录信息存储在数据库中,我想应该是,我的名字/姓氏和时间戳。
但是,我离题了,现在,我不知道如何让php按名字进行查找,然后输出列表
现在我有每一个按钮a-z在军事字母表(阿尔法,布拉沃等)标记,当“a”被选中时,它运行下面的“阿尔法”功能。试图弄清楚在“alpha”“bravo”“charlie”等函数中放入什么,这些函数将使php进入数据库并进行查找并输出列表。
……以下是我目前掌握的情况:

<?php
$servername = "localhost";
$username = "*********";
$password = "*********";
$dbname = "**********";

//Create Connection
global $CONNECTION;
$CONNECTION = new mysqli($servername, $username, $password, $dbname);
//Check Connection
if ($CONNECTION->connect_error) {
    die("Connection To MySQL Database Failed With the Following Error: " . $connection->connect_error);
}
global $SQL; 
$SQL = "SELECT first_name, last_name FROM ppSD_member_data";
global $RESULT; 
$RESULT = $CONNECTION->query($SQL);
if (isset($_POST['alpha'])) {
    alpha();
}
if (isset($_POST['bravo'])) {
    bravo();
}
if (isset($_POST['charlie'])) {
    charlie();
}
if (isset($_POST['delta'])) {
    delta();
}
if (isset($_POST['eko'])) {
    eko();
}
if (isset($_POST['foxtrot'])) {
    foxtrot();
}
if (isset($_POST['golf'])) {
    golf();
}
if (isset($_POST['hotel'])) {
    hotel();
}
if (isset($_POST['india'])) {
    india();
}
if (isset($_POST['juliet'])) {
    juliet();
}
if (isset($_POST['kilo'])) {
    kilo();
}
if (isset($_POST['lima'])) {
    lima();
}
if (isset($_POST['mike'])) {
    mike();
}
if (isset($_POST['november'])) {
    november();
}
if (isset($_POST['oscar'])) {
    oscar();
}
if (isset($_POST['papa'])) {
    papa();
}
if (isset($_POST['quebec'])) {
    quebec();
}
if (isset($_POST['romeo'])) {
    romeo();
}
if (isset($_POST['sierra'])) {
    sierra();
}
if (isset($_POST['tango'])) {
    tango();
}
if (isset($_POST['uniform'])) {
    uniform();
}
if (isset($_POST['victor'])) {
    victor();
}
if (isset($_POST['whiskey'])) {
    whiskey();
}
if (isset($_POST['xray'])) {
    xray();
}
if (isset($_POST['yankee'])) {
    yankee();
}
if (isset($_POST['zulu'])) {
    zulu();
}
echo <<<_END
<html>
    <head>
    <title>The Yard Members</title>
    </head>
<body>
<div align="center">
<h3>Please Select The Letter of Your First Name</h3>
<form method="post" action="display_members.php">
<input type="submit" name="alpha" id="name" value="A" style="height:75px; width:75px" />
<input type="submit" name="bravo" id="name" value="B" style="height:75px; width:75px" />
<input type="submit" name="charlie" id="name" value="C" style="height:75px; width:75px" />
<input type="submit" name="name" id="name" value="D" style="height:75px; width:75px" />
<br>
<input type="submit" value="E" style="height:75px; width:75px" />
<input type="submit" value="F" style="height:75px; width:75px" />
<input type="submit" value="G" style="height:75px; width:75px" />
<input type="submit" value="H" style="height:75px; width:75px" />
<br>
<input type="submit" value="I" style="height:75px; width:75px" />
<input type="submit" value="J" style="height:75px; width:75px" />
<input type="submit" value="K" style="height:75px; width:75px" />
<input type="submit" value="L" style="height:75px; width:75px" />
<br>
<input type="submit" value="M" style="height:75px; width:75px" />
<input type="submit" value="N" style="height:75px; width:75px" />
<input type="submit" value="O" style="height:75px; width:75px" />
<input type="submit" value="P" style="height:75px; width:75px" />
<br>
<input type="submit" value="Q" style="height:75px; width:75px" />
<input type="submit" value="R" style="height:75px; width:75px" />
<input type="submit" value="S" style="height:75px; width:75px" />
<input type="submit" value="T" style="height:75px; width:75px" />
<br>
<input type="submit" value="U" style="height:75px; width:75px" />
<input type="submit" value="V" style="height:75px; width:75px" />
<input type="submit" value="W" style="height:75px; width:75px" />
<input type="submit" value="X" style="height:75px; width:75px" />
<br>
<input type="submit" value="Y" style="height:75px; width:75px" />
<input type="submit" value="Z" style="height:75px; width:75px" />
</form>
</body>
</div>
</html>
_END;
function alpha() {

# while($row = $RESULT->fetch_assoc()) {

    echo "This Is The Alpha Function";
    }
function bravo() {
    echo "This is the Bravo Function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}
function charlie() {
    echo "This is the charlie function";
}

# }

/*if(array_key_exists('name', $_POST)){
    search();
}
function get_post($var)
{
    return mysql_real_escape_string($_POST[$var]);
}
if ($result->num_rows > 0) {
//Output data of each row
    while($row = $result->fetch_assoc()) {
    echo "Name: " . $row["first_name"]. " " . $row["last_name"]. "<br>";
    }
} else {
    echo "No Members";
}

* /

$CONNECTION->close();
?>
628mspwn

628mspwn1#

正如人们所说的代码有点可笑。我想和大家分享一下,希望能给大家一些启示。不想回答你的问题。事实上,我建议删除这个问题,因为我不确定它能给其他人带来多少效用。而“如何进行通配符sql搜索”显然是个愚蠢的问题。
不管怎样。。。可以浓缩为:

//example.com?search_letter=A

$pattern = isset($_REQUEST('search_letter')) ? $_REQUEST('search_letter') : null;

if (empty($pattern)) {
    die('missing search paramter');
}

$pattern = $pattern . '%';
$sql = 'SELECT * FROM users WHERE first_name LIKE ?';

$sth->execute([$pattern]);
$results = $sth->fetchAll();

有什么变化?变量是什么?一封信。你是如何呈现输出的 A 不同于你将如何解释和输出 B ? 不。所以保持干燥(不要重复)。

相关问题