我正试图找出一种能够使用$ row和$ row2的方法。我如何将其纳入while语句?
$result=mysql_query("SELECT * FROM infupdates WHERE username='$_SESSION[username]' ORDER BY date DESC");
$result1=mysql_query("SELECT * FROM infupdates WHERE username='test' ORDER BY date DESC");
while ($row1=mysql_fetch_array($result1,MYSQL_ASSOC))
<td><span class="checkmark"><?php if (($row[onetie]==1)) print "✓";?></span></td>
<td><span class="checkmark"><?php if (($row2[onecro]==1)) print "✓";?></span></td>
答案 0 :(得分:1)
最好在查询中使用OR
尝试
<?php
$result=mysql_query("SELECT * FROM infupdates WHERE '".$_SESSION['username']."' OR username='test' ORDER BY date DESC");
while ($row=mysql_fetch_array($result,MYSQL_ASSOC)) {?>
<td><span class="checkmark"><?php if (($row['onetie']==1)) print "✓";?></span></td>
<td><span class="checkmark"><?php if (($row['onecro']==1)) print "✓";?></span></td>
<?php }?>
同时查看@vutran评论
答案 1 :(得分:0)
while($ row1 = mysql_fetch_array($ result1,MYSQL_ASSOC)|| $ row = mysql_fetch_array($ result,MYSQL_ASSOC)) {
}
否则使用&#34; UNION&#34;在SQL查询
中答案 2 :(得分:0)
您可以使用OR运算符而不是使用两个查询。
<?php $result1=mysql_query("SELECT * FROM infupdates WHERE username='test' OR username=$_SESSION[username] ORDER BY date DESC");
while ($row1=mysql_fetch_array($result1,MYSQL_ASSOC)){ ?>
<td><span class="checkmark"><?php if (($row['onetie']==1)) print "✓";?></span></td>
<td><span class="checkmark"><?php if (($row2['onecro']==1)) print "✓";?></span></td><?php } ?>