1

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

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。让我解释一下,如果值为myuid4,那么我想要u.id=1,或者如果值为fuid4,我想要u.id=6 提前谢谢..任何人都可以帮我..

4

1 回答 1

0

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'
于 2013-08-25T12:55:52.853 回答