gpt4 book ai didi

php - MySQL 连接表列

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

我对此非常陌生,我需要一些帮助。

    <?php
$query = "SELECT owners_dogs.dog_id, dog.name, FROM owners_dogs
LEFT JOIN dog ON owners_dogs.dog_id = dog.id WHERE owners_dogs.person_id=$currId ORDER BY dog.name;";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
if (mysql_num_rows($result)>0) {
echo "<i>Owner of: </i>";
echo "<div style='padding-left:25px;padding-bottom:10px;'>";
while ($line = mysql_fetch_object($result)) {
echo "<a href='details.php?id=$line->dog_id'>";
echo "$line->name </a><? if(dog.certfied == '1') echo "CP" ?><br>";
}
echo "</div>";
}
?>

我遗漏了一些东西......我试图让脚本在dog.certified = 1时回显一些文本

任何帮助将不胜感激

最佳答案

我发现两个可能的错误
1. 要使用certfied 的值进行比较,您应该首先在查询中获取该数据。
2. 并且在while循环中不能直接使用dog.certfied,而是使用$line->certfied

试试这个

$query = "SELECT owners_dogs.dog_id, dog.name, dog.certfied, FROM owners_dogs
LEFT JOIN dog ON owners_dogs.dog_id = dog.id WHERE owners_dogs.person_id=$currId ORDER BY dog.name;";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
if (mysql_num_rows($result) >0 )
{
echo "<i>Owner of: </i>";
echo "<div style='padding-left:25px;padding-bottom:10px;'>";
while ($line = mysql_fetch_object($result))
{
$dog_id = $line->dog_id;
$name = $line->name;


echo "<a href='details.php?id=".$dog_id."'>";
echo $name."</a>";
if($line->certfied == '1');
{
echo "CP"."<br>";
}

}
echo "</div>";
}

关于php - MySQL 连接表列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32737750/

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