-2

I'm trying to figure out a way of being able to use $row and $row2. How can I incorporate that into the while statement?

$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>
1
  • 1
    Just a note: You should be using mysqli_* functions or PDO as the mysql_* is being deprecated.
    – vutran
    Jun 11, 2014 at 6:49

3 Answers 3

1

Better to use OR in query try

<?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 }?>

Also check @vutran comment

0

while ($row1=mysql_fetch_array($result1,MYSQL_ASSOC) || $row=mysql_fetch_array($result,MYSQL_ASSOC)) {

}

Otherwise use "UNION" in sql Query

1
  • thank you for mentioning Union it seems to make the most sense, now trying to get the formatting right Jun 11, 2014 at 7:11
0

You can use OR operator instead of using two queries.

<?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 } ?>

Not the answer you're looking for? Browse other questions tagged or ask your own question.