-3

What is wrong about this code??

echo "<table>";
    echo "<tr><td>Machine Nummer</td><td>Eigenaar</td><td>Status</td><td>Locatie</td></tr>";
    while($row = mysql_fetch_array($result)){
      echo "<tr><td>" . $row['machineid'] . "</td><td> ". $eigenaar=mysql_query("SELECT userName FROM users WHERE userId =" . $row['eigenaar'] ."") ."</td><td>" . $row['status'] . "</td><td>" . $row['locatie'] . "</td></tr>";
    }
    echo "</table>";

$res=mysql_query("SELECT * FROM users WHERE userId=".$_SESSION['user']);
$userRow=mysql_fetch_array($res);


$query = "SELECT * FROM machines WHERE locatie='".$_SESSION['location']."'"; //You don't need a ; like you do in SQL
$result = mysql_query($query);

I want it to output the eigenaar name which equals to the userId but i only get the output:Resource id #9 Resource id #10 Resource id #11.

  • 3
    because, you're putting the wagon before the horse, *as it were* and you can't put a query inside an echo. – Funk Forty Niner Feb 23 '17 at 21:50
  • 3
    *"What is wrong about this code??"* A: everything. It's just utter nonsense; and cargo cult programming as Marc would say. – Funk Forty Niner Feb 23 '17 at 21:51
  • 4
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Feb 23 '17 at 21:52
  • So how can i make it work?? – goedkope tech Feb 23 '17 at 21:55
  • we really have no idea what "IT" is. we dont know what your trying to achieve with this code –  Feb 23 '17 at 22:03
  • yes i am new to this – goedkope tech Feb 23 '17 at 22:05
  • `$row['eigenaar']` is an integer? You should update your driver and use parameterized queries. At a minimum here you should be escaping. – chris85 Feb 23 '17 at 22:09

1 Answers1

0

The answer is to use the INNER JOIN function.