Question

results from the database

10000583221231 --> 10000583221233 --> 2014-02-10
10000583221231 --> 10000358040343 --> 2014-03-03
10000583221231 --> 10000583221546 --> 2014-03-21
10000583221231 --> 10000583221345 --> 2014-04-01

10000583221231 <-- 10000583221233 <-- 2014-02-10
10000583221946 <-- 10000583221233 <-- 2014-03-28
10000583221475 <-- 10000583221233 <-- 2014-04-01
10000583221564 <-- 10000583221233 <-- 2014-04-09
10000583221397 <-- 10000583221233 <-- 2014-04-20

php code:

    <?php
include('db.php');
$result = mysqli_query($con,"SELECT * FROM Aplicatie WHERE id_usr_1 = '10000583221231' ORDER BY date");

while($row = mysqli_fetch_array($result))
  {
  echo $row['id_usr_1'] . " --> " . $row['id_usr_2'] . " --> " . $row['date'];
  echo "<br>";
  }

  echo '<br>';

$result_1 = mysqli_query($con,"SELECT * FROM Aplicatie WHERE id_usr_2 = '10000583221233' ORDER BY date");

while($row = mysqli_fetch_array($result_1))
  {
  echo $row['id_usr_1'] . " <-- " . $row['id_usr_2'] . " <-- " . $row['date'];
  echo "<br>";
  }
?>

and I need to combine them into a table in the following way:

10000583221231 --> 10000583221233 --> 2014-02-10
10000583221231 <-- 10000583221233 <-- 2014-02-10
10000583221231 --> 10000358040343 --> 2014-03-03
10000583221231 --> 10000583221546 --> 2014-03-21
10000583221946 <-- 10000583221233 <-- 2014-03-28
10000583221231 --> 10000583221345 --> 2014-04-01
10000583221475 <-- 10000583221233 <-- 2014-04-01
10000583221564 <-- 10000583221233 <-- 2014-04-09
10000583221397 <-- 10000583221233 <-- 2014-04-20

and must be sorted by date.

what should I do? Thank you for your help.

Was it helpful?

Solution

You could just do 1 query, using OR in your WHERE

<?php
include('db.php');
$result = mysqli_query($con,"SELECT * FROM Aplicatie WHERE id_usr_1 = '10000583221231' OR id_usr_2 = '10000583221233' ORDER BY date");

while($row = mysqli_fetch_array($result))
  {

  $arrows = ($row['id_usr_1'] == '10000583221231') ? " --> " : " <-- ";

  echo $row['id_usr_1'] . $arrows . $row['id_usr_2'] . $arrows . $row['date'];
  echo "<br>";
  }

?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top