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 のような他の行の値が必要です。 の値が 4 の場合はmyuid説明u.id=1し ます。助けて..fuidu.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 に答える