gpt4 book ai didi

php - 如果一个元素很常见,如何从php中的多行中选择数据

转载 作者:行者123 更新时间:2023-11-30 23:14:46 25 4
gpt4 key购买 nike

我的表结构在图片下面的链接中

http://appricart.com/test/ftblstr.png

php代码是:

<?php
include 'config.php';
include 'head.php';
$mid = $_POST['myuid'];
$tf = mysql_query("select f.fuid, f.myuid, u.username as writer, u.avatar from friends as f, users as u where f.myuid='$mid' or f.fuid='$mid' and u.id='$reqid'");
$tfc = mysql_num_rows($tf);
echo "<div style='background: #e9e9e9'>Friends ($tfc)</div>";
while ($frns = mysql_fetch_array($tf))
{
?>
<?php echo $frns['writer']; ?><br/>
<?php
}

?>

这里我想要 u.id 的值,就好像 $mid 的值是 4 那么我想要它的其他行值,比如 1 或 6。让我解释一下如果myuid 的值是 4 那么我想要 u.id=1 或者如果 fuid 的值是 4 我想要 u.id= 6在此先感谢..任何人都可以帮助我..

最佳答案

PHP:

$reqid = $mid == 4 ? 1 : ($fuid == 4 ? 6 : 0); // naturally 0 can be whatever else when both conditions aren't met

SQL:

select f.fuid, f.myuid, u.username as writer, u.avatar
from friends as f, users as u
where f.myuid='$mid' or f.fuid='$mid' and u.id='$reqid'

关于php - 如果一个元素很常见,如何从php中的多行中选择数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18429108/

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