gpt4 book ai didi

php - MYSQL 查询并将输出显示为 html

转载 作者:行者123 更新时间:2023-11-29 18:15:55 24 4
gpt4 key购买 nike

我想显示每个公司的总评级,并且总评级将放在特定类别

代码是这样的

if (isset($_POST['search'])){

$key = $_POST['keyword'];

$com = mysql_query("
SELECT *
FROM company
WHERE id LIKE '%$key%'
OR name LIKE '%$key%'
OR address LIKE '%$key%'
OR city LIKE '%$key%'
OR province LIKE '%$key%'
OR region LIKE '%$key%'
OR country LIKE '%$key%'
OR description LIKE '%$key%'
");
while($comshow = mysql_fetch_array($com)){
$comshowid = $comshow['id'];

echo '
<form method="POST">
<div class = "row">
<div class = "text-right">
<b><input name = "reviewid" style = "margin-right:50%;" class = "text-right" id = "id" type = "text" value = "'.$comshow['id'].'" readonly></b>
</div>
</div>
<div class = "row" style = "margin-left:1%;">
<div class ="col-md-4">
<img src = "'.$comshow['dp'].'" style = "width:80%;">
</div>
<div class = "col-md-6">

<h2><i>'.$comshow['name'].'</i></h2>
<hr />
<p>'.$comshow['description'].'</p>
<h4><b>Ratings</b></h4>
<p>Recruitment:</p>
<p>Tenure:</p>
<p>Separation:</p>
<input class = "btn btn-info" type = "submit" name ="review" value = "REVIEW">
</div>
</div><br><br></form>

';

}

这是评分表 enter image description here

这是公司表 enter image description here这就是输出 enter image description here

最佳答案

@Barmar 是正确的。您需要将您的公司表与评级表连接起来。我还建议有一个名为 ratings_id 的列,它是 rating.id 的外键。然后,您可以在评级表中添加一个名为 rating_value 的列。

插入以下内容:

    ALTER TABLE ‘rating’ ADD ‘rating_value’ INT NULL;
ALTER TABLE ‘company’ ADD ‘ratings_id’ INT NULL;

SELECT c.id, c.name, c.address, c.city, c.province,
c.region, c.country, c.description, c.ratings_id,
r.id, r.rating_value
FROM company c
JOIN rating r
ON c.ratings_is = r.id
AND
c.id LIKE '%$key%'
OR c.name LIKE '%$key%'
OR c.address LIKE '%$key%'
OR city LIKE '%$key%'
OR c.province LIKE '%$key%'
OR c.region LIKE '%$key%'
OR c.country LIKE '%$key%'
OR c.description LIKE '%$key%';

我强烈建议您研究一下 PDO 准备语句,正如许多人在面临 SQL 注入(inject)风险之前所说的那样。

关于php - MYSQL 查询并将输出显示为 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47022898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com